Skip to content

Commit

Permalink
fs: fix options.end of fs.ReadStream()
Browse files Browse the repository at this point in the history
Add a test.

Fixes: nodejs#18116
  • Loading branch information
陈刚 committed Jan 13, 2018
1 parent 036b29b commit 1981fbf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,7 @@ function ReadStream(path, options) {
this.flags = options.flags === undefined ? 'r' : options.flags;
this.mode = options.mode === undefined ? 0o666 : options.mode;

this.start = (typeof this.fd !== 'number' && options.start === undefined) ?
this.start = typeof this.fd !== 'number' && options.start === undefined ?
0 : options.start;
this.end = options.end;
this.autoClose = options.autoClose === undefined ? true : options.autoClose;
Expand Down
13 changes: 13 additions & 0 deletions test/sequential/test-stream2-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,16 @@ w.on('results', function(res) {
});

r.pipe(w);

const optionsEnd = 3;
const optionsEndExpectLength = optionsEnd + 1;
const rOfEnd = new FSReadable(file, {
end: optionsEnd,
});
const wOfEnd = new TestWriter();

wOfEnd.on('results', function(res) {
assert.strictEqual(wOfEnd.length, optionsEndExpectLength);
});

rOfEnd.pipe(wOfEnd);

0 comments on commit 1981fbf

Please sign in to comment.