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) { ...@@ -24,7 +24,8 @@ module.exports = function createReadStream(path, options, cb) {
} }
var offset = options.start || 0; 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) { if (options.end < end) {
end = options.end + 1; // end option is inclusive end = options.end + 1; // end option is inclusive
...@@ -33,6 +34,7 @@ module.exports = function createReadStream(path, options, cb) { ...@@ -33,6 +34,7 @@ module.exports = function createReadStream(path, options, cb) {
var close = request.bind(undefined, 'close', file, connection); var close = request.bind(undefined, 'close', file, connection);
var stream = new Readable(); var stream = new Readable();
stream.fileSize = fileSize;
if (shouldClose) { if (shouldClose) {
stream._destroy = function(err, cb) { stream._destroy = function(err, cb) {
close(function(err2) { close(function(err2) {
......
...@@ -58,12 +58,12 @@ const tests = { ...@@ -58,12 +58,12 @@ const tests = {
const fd = yield client.open(file, 'r'); const fd = yield client.open(file, 'r');
$d.call(client, 'close', fd); $d.call(client, 'close', fd);
t.same( const readStream = yield client.createReadStream('', {
yield getStream.buffer( autoClose: false,
yield client.createReadStream('', { autoClose: false, fd }) fd,
), });
data t.same(yield getStream.buffer(readStream), data);
); t.same(readStream.fileSize, data.length);
}) })
), ),
createWriteStream: defer( 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