Skip to content

Commit b343cb6

Browse files
陈刚MylesBorins
陈刚
authored andcommitted
fs: fix options.end of fs.ReadStream()
Fixes: nodejs#18116 PR-URL: nodejs#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 299482c commit b343cb6

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
@@ -1942,7 +1942,8 @@ function ReadStream(path, options) {
19421942
this.flags = options.flags === undefined ? 'r' : options.flags;
19431943
this.mode = options.mode === undefined ? 0o666 : options.mode;
19441944

1945-
this.start = options.start;
1945+
this.start = typeof this.fd !== 'number' && options.start === undefined ?
1946+
0 : options.start;
19461947
this.end = options.end;
19471948
this.autoClose = options.autoClose === undefined ? true : options.autoClose;
19481949
this.pos = undefined;

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

+14
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@ assert.throws(function() {
157157
}));
158158
}
159159

160+
{
161+
// Verify that end works when start is not specified.
162+
const stream = new fs.createReadStream(rangeFile, { end: 1 });
163+
stream.data = '';
164+
165+
stream.on('data', function(chunk) {
166+
stream.data += chunk;
167+
});
168+
169+
stream.on('end', common.mustCall(function() {
170+
assert.strictEqual('xy', stream.data);
171+
}));
172+
}
173+
160174
{
161175
// pause and then resume immediately.
162176
const pauseRes = fs.createReadStream(rangeFile);

0 commit comments

Comments
 (0)