GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: acknowledge `signal` option in `filehandle.createReadStream()` · nodejs/node@0decaab

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • fs.md
  • test/parallel
    • test-fs-read-stream-file-handle.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/fs.md‎

Copy file name to clipboardExpand all lines: doc/api/fs.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ added: v16.11.0
265265
* `start` {integer}
266266
* `end` {integer} **Default:** `Infinity`
267267
* `highWaterMark` {integer} **Default:** `64 * 1024`
268+
* `signal` {AbortSignal|undefined} **Default:** `undefined`
268269
* Returns: {fs.ReadStream}
269270
270271
Unlike the 16 KiB default `highWaterMark` for a {stream.Readable}, the stream
Collapse file

‎test/parallel/test-fs-read-stream-file-handle.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-read-stream-file-handle.js
+72Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,75 @@ fs.promises.open(file, 'r').then((handle) => {
8080
assert.strictEqual(output, input);
8181
}));
8282
}).then(common.mustCall());
83+
84+
// AbortSignal option test
85+
fs.promises.open(file, 'r').then((handle) => {
86+
const controller = new AbortController();
87+
const { signal } = controller;
88+
const stream = handle.createReadStream({ signal });
89+
90+
stream.on('data', common.mustNotCall());
91+
stream.on('end', common.mustNotCall());
92+
93+
stream.on('error', common.mustCall((err) => {
94+
assert.strictEqual(err.name, 'AbortError');
95+
}));
96+
97+
stream.on('close', common.mustCall(() => {
98+
handle.close();
99+
}));
100+
101+
controller.abort();
102+
}).then(common.mustCall());
103+
104+
// Already-aborted signal test
105+
fs.promises.open(file, 'r').then((handle) => {
106+
const signal = AbortSignal.abort();
107+
const stream = handle.createReadStream({ signal });
108+
109+
stream.on('data', common.mustNotCall());
110+
stream.on('end', common.mustNotCall());
111+
112+
stream.on('error', common.mustCall((err) => {
113+
assert.strictEqual(err.name, 'AbortError');
114+
}));
115+
116+
stream.on('close', common.mustCall(() => {
117+
handle.close();
118+
}));
119+
}).then(common.mustCall());
120+
121+
// Invalid signal type test
122+
fs.promises.open(file, 'r').then((handle) => {
123+
for (const signal of [1, {}, [], '', null, NaN, 1n, () => {}, Symbol(), false, true]) {
124+
assert.throws(() => {
125+
handle.createReadStream({ signal });
126+
}, {
127+
code: 'ERR_INVALID_ARG_TYPE',
128+
name: 'TypeError',
129+
});
130+
}
131+
return handle.close();
132+
}).then(common.mustCall());
133+
134+
// Custom abort reason test
135+
fs.promises.open(file, 'r').then((handle) => {
136+
const controller = new AbortController();
137+
const { signal } = controller;
138+
const reason = new Error('some silly abort reason');
139+
const stream = handle.createReadStream({ signal });
140+
141+
stream.on('data', common.mustNotCall());
142+
stream.on('end', common.mustNotCall());
143+
144+
stream.on('error', common.mustCall((err) => {
145+
assert.strictEqual(err.name, 'AbortError');
146+
assert.strictEqual(err.cause, reason);
147+
}));
148+
149+
stream.on('close', common.mustCall(() => {
150+
handle.close();
151+
}));
152+
153+
controller.abort(reason);
154+
}).then(common.mustCall());

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.