diff --git a/lib/fs.js b/lib/fs.js index e6ab7ba6d6986d..5efccceb544d20 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1919,7 +1919,8 @@ function ReadStream(path, options) { this.flags = options.flags === undefined ? 'r' : options.flags; this.mode = options.mode === undefined ? 0o666 : options.mode; - this.start = options.start; + this.start = typeof this.fd !== 'number' && options.start === undefined ? + 0 : options.start; this.end = options.end; this.autoClose = options.autoClose === undefined ? true : options.autoClose; this.pos = undefined; diff --git a/test/parallel/test-fs-read-stream.js b/test/parallel/test-fs-read-stream.js index bab809f72c19ce..95d5fbeaef9973 100644 --- a/test/parallel/test-fs-read-stream.js +++ b/test/parallel/test-fs-read-stream.js @@ -132,6 +132,20 @@ stream.on('end', function() { assert.strictEqual('x', stream.data); }); +{ + // Verify that end works when start is not specified. + const stream = new fs.createReadStream(rangeFile, { end: 1 }); + stream.data = ''; + + stream.on('data', function(chunk) { + stream.data += chunk; + }); + + stream.on('end', common.mustCall(function() { + assert.strictEqual('xy', stream.data); + })); +} + // pause and then resume immediately. const pauseRes = fs.createReadStream(rangeFile); pauseRes.pause();