Commit 441a21e1 authored by Peter Keuter's avatar Peter Keuter Committed by Julien Fontanet

feat(createReadStream): add `.fileSize` (#60)

parent aa587253
......@@ -24,7 +24,8 @@ module.exports = function createReadStream(path, options, cb) {
}
var offset = options.start || 0;
var end = BigInt.fromBuffer(file.EndofFile).toNumber();
var fileSize = BigInt.fromBuffer(file.EndofFile).toNumber();
var end = fileSize;
if (options.end < end) {
end = options.end + 1; // end option is inclusive
......@@ -33,6 +34,7 @@ module.exports = function createReadStream(path, options, cb) {
var close = request.bind(undefined, 'close', file, connection);
var stream = new Readable();
stream.fileSize = fileSize;
if (shouldClose) {
stream._destroy = function(err, cb) {
close(function(err2) {
......
......@@ -58,12 +58,12 @@ const tests = {
const fd = yield client.open(file, 'r');
$d.call(client, 'close', fd);
t.same(
yield getStream.buffer(
yield client.createReadStream('', { autoClose: false, fd })
),
data
);
const readStream = yield client.createReadStream('', {
autoClose: false,
fd,
});
t.same(yield getStream.buffer(readStream), data);
t.same(readStream.fileSize, data.length);
})
),
createWriteStream: defer(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment