pauls-dat-api
Version:
Library of functions that make working with dat / hyperdrive easier.
26 lines (24 loc) • 809 B
JavaScript
var _require = require('./common'),maybe = _require.maybe,toBeakerError = _require.toBeakerError;
// lookup information about a file
function stat(archive, name, cb) {
return maybe(cb, new Promise(function (resolve, reject) {
// run stat operation
archive.stat(name, function (err, st) {
if (err) reject(toBeakerError(err, 'stat'));else
{
// read download status
st.downloaded = 0;
if (!archive.key) {
// fs, not an archive
st.downloaded = st.blocks;
} else if (st.isFile()) {
if (archive.content && archive.content.length) {
st.downloaded = archive.content.downloaded(st.offset, st.offset + st.blocks);
}
}
resolve(st);
}
});
}));
}
module.exports = { stat };
;