Skip to content

Commit df038ad

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 eaa30e4 commit df038ad

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

1922-
this.start = options.start;
1922+
this.start = typeof this.fd !== 'number' && options.start === undefined ?
1923+
0 : options.start;
19231924
this.end = options.end;
19241925
this.autoClose = options.autoClose === undefined ? true : options.autoClose;
19251926
this.pos = undefined;

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

+14
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ stream.on('end', function() {
132132
assert.strictEqual('x', stream.data);
133133
});
134134

135+
{
136+
// Verify that end works when start is not specified.
137+
const stream = new fs.createReadStream(rangeFile, { end: 1 });
138+
stream.data = '';
139+
140+
stream.on('data', function(chunk) {
141+
stream.data += chunk;
142+
});
143+
144+
stream.on('end', common.mustCall(function() {
145+
assert.strictEqual('xy', stream.data);
146+
}));
147+
}
148+
135149
// pause and then resume immediately.
136150
const pauseRes = fs.createReadStream(rangeFile);
137151
pauseRes.pause();

0 commit comments

Comments
 (0)