Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,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
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you write this like:

{
  // Verify that end works when start is not specified.
  const end = 3;
  const r = new FSReadable(file, { end });
  const w = new TestWriter();

  w.on('results', common.mustCall((res) => {
    assert.strictEqual(w.length, end + 1);
  }));

  r.pipe(w);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

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);