Skip to content

Commit 778d57c

Browse files
陈刚evanlucas
陈刚
authored andcommitted
fs: fix options.end of fs.ReadStream()
Fixes: #18116 PR-URL: #18121 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com>
1 parent 1d74c33 commit 778d57c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/fs.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,8 @@ function ReadStream(path, options) {
19971997
this.flags = options.flags === undefined ? 'r' : options.flags;
19981998
this.mode = options.mode === undefined ? 0o666 : options.mode;
19991999

2000-
this.start = options.start;
2000+
this.start = typeof this.fd !== 'number' && options.start === undefined ?
2001+
0 : options.start;
20012002
this.end = options.end;
20022003
this.autoClose = options.autoClose === undefined ? true : options.autoClose;
20032004
this.pos = undefined;

test/parallel/test-fs-read-stream.js

+14
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ common.expectsError(
164164
}));
165165
}
166166

167+
{
168+
// Verify that end works when start is not specified.
169+
const stream = new fs.createReadStream(rangeFile, { end: 1 });
170+
stream.data = '';
171+
172+
stream.on('data', function(chunk) {
173+
stream.data += chunk;
174+
});
175+
176+
stream.on('end', common.mustCall(function() {
177+
assert.strictEqual('xy', stream.data);
178+
}));
179+
}
180+
167181
{
168182
// pause and then resume immediately.
169183
const pauseRes = fs.createReadStream(rangeFile);

0 commit comments

Comments
 (0)