Skip to content

Commit df038ad

Browse files
陈刚MylesBorins
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 eaa30e4 commit df038ad

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎lib/fs.js‎

Lines changed: 2 additions & 1 deletion
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=typeofthis.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‎

Lines changed: 14 additions & 0 deletions
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+
conststream=newfs.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
constpauseRes=fs.createReadStream(rangeFile);
137151
pauseRes.pause();

0 commit comments

Comments
 (0)