mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 13:11:36 +00:00
fs: fix options.end of fs.ReadStream()
Fixes: https://github.com/nodejs/node/issues/18116 PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
5aa0f3ee16
commit
82bdf8fba2
@ -2267,7 +2267,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;
|
||||
|
@ -164,6 +164,20 @@ common.expectsError(
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
// Verify that end works when start is not specified.
|
||||
const stream = new fs.createReadStream(rangeFile, { end: 1 });
|
||||
stream.data = '';
|
||||
|
||||
stream.on('data', function(chunk) {
|
||||
stream.data += chunk;
|
||||
});
|
||||
|
||||
stream.on('end', common.mustCall(function() {
|
||||
assert.strictEqual('xy', stream.data);
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
// pause and then resume immediately.
|
||||
const pauseRes = fs.createReadStream(rangeFile);
|
||||
|
Loading…
Reference in New Issue
Block a user