Skip to content

Commit

Permalink
fs: fix options.end of fs.ReadStream()
Browse files Browse the repository at this point in the history
Fixes: nodejs#18116
PR-URL: nodejs#18121
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Weijia Wang <[email protected]>
  • Loading branch information
陈刚 authored and MayaLekova committed May 8, 2018
1 parent c3e7596 commit 717fc05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2267,7 +2267,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;
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-fs-read-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ common.expectsError(
}));
}

{
// 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);
Expand Down

0 comments on commit 717fc05

Please sign in to comment.