Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: acknowledge signal option in filehandle.createReadStream() #55148

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ added: v16.11.0
* `start` {integer}
* `end` {integer} **Default:** `Infinity`
* `highWaterMark` {integer} **Default:** `64 * 1024`
* `signal` {AbortSignal|undefined} **Default:** `undefined`
* Returns: {fs.ReadStream}

Unlike the 16 KiB default `highWaterMark` for a {stream.Readable}, the stream
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-fs-read-stream-file-handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,22 @@ fs.promises.open(file, 'r').then((handle) => {
assert.strictEqual(output, input);
}));
}).then(common.mustCall());

fs.promises.open(file, 'r').then((handle) => {
LiviaMedeiros marked this conversation as resolved.
Show resolved Hide resolved
const controller = new AbortController();
const { signal } = controller;
const stream = handle.createReadStream({ signal });
LiviaMedeiros marked this conversation as resolved.
Show resolved Hide resolved

stream.on('data', common.mustNotCall());
stream.on('end', common.mustNotCall());

stream.on('error', common.mustCall((err) => {
assert.strictEqual(err.name, 'AbortError');
}));

stream.on('close', common.mustCall(() => {
handle.close();
}));

controller.abort();
LiviaMedeiros marked this conversation as resolved.
Show resolved Hide resolved
}).then(common.mustCall());
LiviaMedeiros marked this conversation as resolved.
Show resolved Hide resolved
Loading