@types/node 18.11.5 → 20.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- node/README.md +2 -2
- node/assert.d.ts +86 -75
- node/async_hooks.d.ts +66 -37
- node/buffer.d.ts +193 -100
- node/child_process.d.ts +82 -56
- node/cluster.d.ts +12 -12
- node/console.d.ts +5 -5
- node/crypto.d.ts +233 -235
- node/dgram.d.ts +15 -15
- node/diagnostics_channel.d.ts +59 -21
- node/dns/promises.d.ts +50 -6
- node/dns.d.ts +26 -17
- node/domain.d.ts +4 -4
- node/events.d.ts +111 -65
- node/fs/promises.d.ts +99 -47
- node/fs.d.ts +244 -73
- node/globals.d.ts +6 -3
- node/http.d.ts +265 -148
- node/http2.d.ts +42 -47
- node/https.d.ts +53 -153
- node/index.d.ts +2 -1
- node/inspector.d.ts +10 -3
- node/module.d.ts +6 -4
- node/net.d.ts +32 -15
- node/os.d.ts +27 -16
- node/package.json +9 -4
- node/path.d.ts +4 -4
- node/perf_hooks.d.ts +28 -15
- node/process.d.ts +49 -46
- node/punycode.d.ts +1 -1
- node/querystring.d.ts +5 -5
- node/readline/promises.d.ts +65 -63
- node/readline.d.ts +32 -159
- node/repl.d.ts +20 -20
- node/stream/consumers.d.ts +1 -1
- node/stream.d.ts +950 -869
- node/string_decoder.d.ts +6 -6
- node/test.d.ts +877 -139
- node/timers/promises.d.ts +26 -1
- node/timers.d.ts +125 -4
- node/tls.d.ts +120 -29
- node/trace_events.d.ts +20 -9
- node/ts4.8/assert.d.ts +86 -75
- node/ts4.8/async_hooks.d.ts +66 -37
- node/ts4.8/buffer.d.ts +193 -101
- node/ts4.8/child_process.d.ts +82 -56
- node/ts4.8/cluster.d.ts +12 -12
- node/ts4.8/console.d.ts +5 -5
- node/ts4.8/crypto.d.ts +230 -233
- node/ts4.8/dgram.d.ts +15 -15
- node/ts4.8/diagnostics_channel.d.ts +59 -21
- node/ts4.8/dns/promises.d.ts +50 -6
- node/ts4.8/dns.d.ts +26 -17
- node/ts4.8/domain.d.ts +4 -4
- node/ts4.8/events.d.ts +111 -65
- node/ts4.8/fs/promises.d.ts +97 -46
- node/ts4.8/fs.d.ts +244 -73
- node/ts4.8/globals.d.ts +21 -12
- node/ts4.8/http.d.ts +265 -148
- node/ts4.8/http2.d.ts +42 -47
- node/ts4.8/https.d.ts +53 -153
- node/ts4.8/inspector.d.ts +10 -3
- node/ts4.8/module.d.ts +6 -4
- node/ts4.8/net.d.ts +33 -16
- node/ts4.8/os.d.ts +27 -16
- node/ts4.8/path.d.ts +4 -4
- node/ts4.8/perf_hooks.d.ts +28 -15
- node/ts4.8/process.d.ts +49 -46
- node/ts4.8/punycode.d.ts +1 -1
- node/ts4.8/querystring.d.ts +5 -5
- node/ts4.8/readline/promises.d.ts +65 -63
- node/ts4.8/readline.d.ts +32 -159
- node/ts4.8/repl.d.ts +20 -20
- node/ts4.8/stream/consumers.d.ts +1 -1
- node/ts4.8/stream.d.ts +192 -140
- node/ts4.8/string_decoder.d.ts +6 -6
- node/ts4.8/test.d.ts +877 -139
- node/ts4.8/timers/promises.d.ts +26 -1
- node/ts4.8/timers.d.ts +125 -4
- node/ts4.8/tls.d.ts +120 -29
- node/ts4.8/trace_events.d.ts +20 -9
- node/ts4.8/tty.d.ts +4 -5
- node/ts4.8/url.d.ts +46 -42
- node/ts4.8/util.d.ts +325 -123
- node/ts4.8/v8.d.ts +253 -14
- node/ts4.8/vm.d.ts +417 -32
- node/ts4.8/wasi.d.ts +13 -19
- node/ts4.8/worker_threads.d.ts +38 -34
- node/ts4.8/zlib.d.ts +11 -11
- node/tty.d.ts +4 -5
- node/url.d.ts +46 -42
- node/util.d.ts +325 -123
- node/v8.d.ts +253 -14
- node/vm.d.ts +417 -32
- node/wasi.d.ts +13 -19
- node/worker_threads.d.ts +38 -34
- node/zlib.d.ts +11 -11
node/ts4.8/repl.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `repl` module provides a Read-Eval-Print-Loop (REPL) implementation
|
|
3
|
-
* is available both as a standalone program or includible in other
|
|
4
|
-
* It can be accessed using:
|
|
2
|
+
* The `node:repl` module provides a Read-Eval-Print-Loop (REPL) implementation
|
|
3
|
+
* that is available both as a standalone program or includible in other
|
|
4
|
+
* applications. It can be accessed using:
|
|
5
5
|
*
|
|
6
6
|
* ```js
|
|
7
|
-
* const repl = require('repl');
|
|
7
|
+
* const repl = require('node:repl');
|
|
8
8
|
* ```
|
|
9
|
-
* @see [source](https://github.com/nodejs/node/blob/
|
|
9
|
+
* @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/repl.js)
|
|
10
10
|
*/
|
|
11
11
|
declare module 'repl' {
|
|
12
12
|
import { Interface, Completer, AsyncCompleter } from 'node:readline';
|
|
@@ -41,8 +41,8 @@ declare module 'repl' {
|
|
|
41
41
|
* error with `repl.Recoverable` to indicate the input was incomplete and prompt for
|
|
42
42
|
* additional lines.
|
|
43
43
|
*
|
|
44
|
-
* @see https://nodejs.org/dist/latest-
|
|
45
|
-
* @see https://nodejs.org/dist/latest-
|
|
44
|
+
* @see https://nodejs.org/dist/latest-v20.x/docs/api/repl.html#repl_default_evaluation
|
|
45
|
+
* @see https://nodejs.org/dist/latest-v20.x/docs/api/repl.html#repl_custom_evaluation_functions
|
|
46
46
|
*/
|
|
47
47
|
eval?: REPLEval | undefined;
|
|
48
48
|
/**
|
|
@@ -74,13 +74,13 @@ declare module 'repl' {
|
|
|
74
74
|
* The function to invoke to format the output of each command before writing to `output`.
|
|
75
75
|
* Default: a wrapper for `util.inspect`.
|
|
76
76
|
*
|
|
77
|
-
* @see https://nodejs.org/dist/latest-
|
|
77
|
+
* @see https://nodejs.org/dist/latest-v20.x/docs/api/repl.html#repl_customizing_repl_output
|
|
78
78
|
*/
|
|
79
79
|
writer?: REPLWriter | undefined;
|
|
80
80
|
/**
|
|
81
81
|
* An optional function used for custom Tab auto completion.
|
|
82
82
|
*
|
|
83
|
-
* @see https://nodejs.org/dist/latest-
|
|
83
|
+
* @see https://nodejs.org/dist/latest-v20.x/docs/api/readline.html#readline_use_of_the_completer_function
|
|
84
84
|
*/
|
|
85
85
|
completer?: Completer | AsyncCompleter | undefined;
|
|
86
86
|
/**
|
|
@@ -124,7 +124,7 @@ declare module 'repl' {
|
|
|
124
124
|
* or directly using the JavaScript `new` keyword.
|
|
125
125
|
*
|
|
126
126
|
* ```js
|
|
127
|
-
* const repl = require('repl');
|
|
127
|
+
* const repl = require('node:repl');
|
|
128
128
|
*
|
|
129
129
|
* const options = { useColors: true };
|
|
130
130
|
*
|
|
@@ -162,33 +162,33 @@ declare module 'repl' {
|
|
|
162
162
|
/**
|
|
163
163
|
* A value indicating whether the REPL is currently in "editor mode".
|
|
164
164
|
*
|
|
165
|
-
* @see https://nodejs.org/dist/latest-
|
|
165
|
+
* @see https://nodejs.org/dist/latest-v20.x/docs/api/repl.html#repl_commands_and_special_keys
|
|
166
166
|
*/
|
|
167
167
|
readonly editorMode: boolean;
|
|
168
168
|
/**
|
|
169
169
|
* A value indicating whether the `_` variable has been assigned.
|
|
170
170
|
*
|
|
171
|
-
* @see https://nodejs.org/dist/latest-
|
|
171
|
+
* @see https://nodejs.org/dist/latest-v20.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable
|
|
172
172
|
*/
|
|
173
173
|
readonly underscoreAssigned: boolean;
|
|
174
174
|
/**
|
|
175
175
|
* The last evaluation result from the REPL (assigned to the `_` variable inside of the REPL).
|
|
176
176
|
*
|
|
177
|
-
* @see https://nodejs.org/dist/latest-
|
|
177
|
+
* @see https://nodejs.org/dist/latest-v20.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable
|
|
178
178
|
*/
|
|
179
179
|
readonly last: any;
|
|
180
180
|
/**
|
|
181
181
|
* A value indicating whether the `_error` variable has been assigned.
|
|
182
182
|
*
|
|
183
183
|
* @since v9.8.0
|
|
184
|
-
* @see https://nodejs.org/dist/latest-
|
|
184
|
+
* @see https://nodejs.org/dist/latest-v20.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable
|
|
185
185
|
*/
|
|
186
186
|
readonly underscoreErrAssigned: boolean;
|
|
187
187
|
/**
|
|
188
188
|
* The last error raised inside the REPL (assigned to the `_error` variable inside of the REPL).
|
|
189
189
|
*
|
|
190
190
|
* @since v9.8.0
|
|
191
|
-
* @see https://nodejs.org/dist/latest-
|
|
191
|
+
* @see https://nodejs.org/dist/latest-v20.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable
|
|
192
192
|
*/
|
|
193
193
|
readonly lastError: any;
|
|
194
194
|
/**
|
|
@@ -240,7 +240,7 @@ declare module 'repl' {
|
|
|
240
240
|
*
|
|
241
241
|
* `REPLServer` cannot be subclassed due to implementation specifics in NodeJS.
|
|
242
242
|
*
|
|
243
|
-
* @see https://nodejs.org/dist/latest-
|
|
243
|
+
* @see https://nodejs.org/dist/latest-v20.x/docs/api/repl.html#repl_class_replserver
|
|
244
244
|
*/
|
|
245
245
|
private constructor();
|
|
246
246
|
/**
|
|
@@ -251,7 +251,7 @@ declare module 'repl' {
|
|
|
251
251
|
* The following example shows two new commands added to the REPL instance:
|
|
252
252
|
*
|
|
253
253
|
* ```js
|
|
254
|
-
* const repl = require('repl');
|
|
254
|
+
* const repl = require('node:repl');
|
|
255
255
|
*
|
|
256
256
|
* const replServer = repl.start({ prompt: '> ' });
|
|
257
257
|
* replServer.defineCommand('sayhello', {
|
|
@@ -260,7 +260,7 @@ declare module 'repl' {
|
|
|
260
260
|
* this.clearBufferedCommand();
|
|
261
261
|
* console.log(`Hello, ${name}!`);
|
|
262
262
|
* this.displayPrompt();
|
|
263
|
-
* }
|
|
263
|
+
* },
|
|
264
264
|
* });
|
|
265
265
|
* replServer.defineCommand('saybye', function saybye() {
|
|
266
266
|
* console.log('Goodbye!');
|
|
@@ -401,7 +401,7 @@ declare module 'repl' {
|
|
|
401
401
|
* If `options` is a string, then it specifies the input prompt:
|
|
402
402
|
*
|
|
403
403
|
* ```js
|
|
404
|
-
* const repl = require('repl');
|
|
404
|
+
* const repl = require('node:repl');
|
|
405
405
|
*
|
|
406
406
|
* // a Unix style prompt
|
|
407
407
|
* repl.start('$ ');
|
|
@@ -412,7 +412,7 @@ declare module 'repl' {
|
|
|
412
412
|
/**
|
|
413
413
|
* Indicates a recoverable error that a `REPLServer` can use to support multi-line input.
|
|
414
414
|
*
|
|
415
|
-
* @see https://nodejs.org/dist/latest-
|
|
415
|
+
* @see https://nodejs.org/dist/latest-v20.x/docs/api/repl.html#repl_recoverable_errors
|
|
416
416
|
*/
|
|
417
417
|
class Recoverable extends SyntaxError {
|
|
418
418
|
err: Error;
|
node/ts4.8/stream/consumers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare module 'stream/consumers' {
|
|
2
|
-
import { Blob as NodeBlob } from
|
|
2
|
+
import { Blob as NodeBlob } from 'node:buffer';
|
|
3
3
|
import { Readable } from 'node:stream';
|
|
4
4
|
function buffer(stream: NodeJS.ReadableStream | Readable | AsyncIterator<any>): Promise<Buffer>;
|
|
5
5
|
function text(stream: NodeJS.ReadableStream | Readable | AsyncIterator<any>): Promise<string>;
|
node/ts4.8/stream.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A stream is an abstract interface for working with streaming data in Node.js.
|
|
3
|
-
* The `stream` module provides an API for implementing the stream interface.
|
|
3
|
+
* The `node:stream` module provides an API for implementing the stream interface.
|
|
4
4
|
*
|
|
5
5
|
* There are many stream objects provided by Node.js. For instance, a `request to an HTTP server` and `process.stdout` are both stream instances.
|
|
6
6
|
*
|
|
7
7
|
* Streams can be readable, writable, or both. All streams are instances of `EventEmitter`.
|
|
8
8
|
*
|
|
9
|
-
* To access the `stream` module:
|
|
9
|
+
* To access the `node:stream` module:
|
|
10
10
|
*
|
|
11
11
|
* ```js
|
|
12
|
-
* const stream = require('stream');
|
|
12
|
+
* const stream = require('node:stream');
|
|
13
13
|
* ```
|
|
14
14
|
*
|
|
15
|
-
* The `stream` module is useful for creating new types of stream instances.
|
|
16
|
-
* usually not necessary to use the `stream` module to consume streams.
|
|
17
|
-
* @see [source](https://github.com/nodejs/node/blob/
|
|
15
|
+
* The `node:stream` module is useful for creating new types of stream instances.
|
|
16
|
+
* It is usually not necessary to use the `node:stream` module to consume streams.
|
|
17
|
+
* @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/stream.js)
|
|
18
18
|
*/
|
|
19
19
|
declare module 'stream' {
|
|
20
20
|
import { EventEmitter, Abortable } from 'node:events';
|
|
21
|
-
import { Blob as NodeBlob } from
|
|
21
|
+
import { Blob as NodeBlob } from 'node:buffer';
|
|
22
22
|
import * as streamPromises from 'node:stream/promises';
|
|
23
23
|
import * as streamConsumers from 'node:stream/consumers';
|
|
24
24
|
import * as streamWeb from 'node:stream/web';
|
|
@@ -124,12 +124,12 @@ declare module 'stream' {
|
|
|
124
124
|
readonly readableObjectMode: boolean;
|
|
125
125
|
/**
|
|
126
126
|
* Is `true` after `readable.destroy()` has been called.
|
|
127
|
-
* @since
|
|
127
|
+
* @since v8.0.0
|
|
128
128
|
*/
|
|
129
129
|
destroyed: boolean;
|
|
130
130
|
/**
|
|
131
|
-
* Is true after 'close' has been emitted.
|
|
132
|
-
* @since
|
|
131
|
+
* Is `true` after `'close'` has been emitted.
|
|
132
|
+
* @since v18.0.0
|
|
133
133
|
*/
|
|
134
134
|
readonly closed: boolean;
|
|
135
135
|
/**
|
|
@@ -310,7 +310,7 @@ declare module 'stream' {
|
|
|
310
310
|
* the method does nothing.
|
|
311
311
|
*
|
|
312
312
|
* ```js
|
|
313
|
-
* const fs = require('fs');
|
|
313
|
+
* const fs = require('node:fs');
|
|
314
314
|
* const readable = getReadableStreamSomehow();
|
|
315
315
|
* const writable = fs.createWriteStream('file.txt');
|
|
316
316
|
* // All the data from readable goes into 'file.txt',
|
|
@@ -348,7 +348,7 @@ declare module 'stream' {
|
|
|
348
348
|
* // Pull off a header delimited by \n\n.
|
|
349
349
|
* // Use unshift() if we get too much.
|
|
350
350
|
* // Call the callback with (error, header, stream).
|
|
351
|
-
* const { StringDecoder } = require('string_decoder');
|
|
351
|
+
* const { StringDecoder } = require('node:string_decoder');
|
|
352
352
|
* function parseHeader(stream, callback) {
|
|
353
353
|
* stream.on('error', callback);
|
|
354
354
|
* stream.on('readable', onReadable);
|
|
@@ -388,14 +388,14 @@ declare module 'stream' {
|
|
|
388
388
|
* however it is best to simply avoid calling `readable.unshift()` while in the
|
|
389
389
|
* process of performing a read.
|
|
390
390
|
* @since v0.9.11
|
|
391
|
-
* @param chunk Chunk of data to unshift onto the read queue. For streams not operating in object mode, `chunk` must be a string, `Buffer`, `Uint8Array
|
|
391
|
+
* @param chunk Chunk of data to unshift onto the read queue. For streams not operating in object mode, `chunk` must be a string, `Buffer`, `Uint8Array`, or `null`. For object mode
|
|
392
392
|
* streams, `chunk` may be any JavaScript value.
|
|
393
393
|
* @param encoding Encoding of string chunks. Must be a valid `Buffer` encoding, such as `'utf8'` or `'ascii'`.
|
|
394
394
|
*/
|
|
395
395
|
unshift(chunk: any, encoding?: BufferEncoding): void;
|
|
396
396
|
/**
|
|
397
|
-
* Prior to Node.js 0.10, streams did not implement the entire `stream`
|
|
398
|
-
*
|
|
397
|
+
* Prior to Node.js 0.10, streams did not implement the entire `node:stream`module API as it is currently defined. (See `Compatibility` for more
|
|
398
|
+
* information.)
|
|
399
399
|
*
|
|
400
400
|
* When using an older Node.js library that emits `'data'` events and has a {@link pause} method that is advisory only, the`readable.wrap()` method can be used to create a `Readable`
|
|
401
401
|
* stream that uses
|
|
@@ -407,7 +407,7 @@ declare module 'stream' {
|
|
|
407
407
|
*
|
|
408
408
|
* ```js
|
|
409
409
|
* const { OldReader } = require('./old-api-module.js');
|
|
410
|
-
* const { Readable } = require('stream');
|
|
410
|
+
* const { Readable } = require('node:stream');
|
|
411
411
|
* const oreader = new OldReader();
|
|
412
412
|
* const myReader = new Readable().wrap(oreader);
|
|
413
413
|
*
|
|
@@ -534,7 +534,7 @@ declare module 'stream' {
|
|
|
534
534
|
static toWeb(streamWritable: Writable): streamWeb.WritableStream;
|
|
535
535
|
/**
|
|
536
536
|
* Is `true` if it is safe to call `writable.write()`, which means
|
|
537
|
-
* the stream has not been destroyed, errored or ended.
|
|
537
|
+
* the stream has not been destroyed, errored, or ended.
|
|
538
538
|
* @since v11.4.0
|
|
539
539
|
*/
|
|
540
540
|
readonly writable: boolean;
|
|
@@ -578,8 +578,8 @@ declare module 'stream' {
|
|
|
578
578
|
*/
|
|
579
579
|
destroyed: boolean;
|
|
580
580
|
/**
|
|
581
|
-
* Is true after 'close' has been emitted.
|
|
582
|
-
* @since
|
|
581
|
+
* Is `true` after `'close'` has been emitted.
|
|
582
|
+
* @since v18.0.0
|
|
583
583
|
*/
|
|
584
584
|
readonly closed: boolean;
|
|
585
585
|
/**
|
|
@@ -588,7 +588,7 @@ declare module 'stream' {
|
|
|
588
588
|
*/
|
|
589
589
|
readonly errored: Error | null;
|
|
590
590
|
/**
|
|
591
|
-
* Is `true` if the stream's buffer has been full and stream will emit 'drain'
|
|
591
|
+
* Is `true` if the stream's buffer has been full and stream will emit `'drain'`.
|
|
592
592
|
* @since v15.2.0, v14.17.0
|
|
593
593
|
*/
|
|
594
594
|
readonly writableNeedDrain: boolean;
|
|
@@ -678,7 +678,7 @@ declare module 'stream' {
|
|
|
678
678
|
*
|
|
679
679
|
* ```js
|
|
680
680
|
* // Write 'hello, ' and then end with 'world!'.
|
|
681
|
-
* const fs = require('fs');
|
|
681
|
+
* const fs = require('node:fs');
|
|
682
682
|
* const file = fs.createWriteStream('example.txt');
|
|
683
683
|
* file.write('hello, ');
|
|
684
684
|
* file.end('world!');
|
|
@@ -864,7 +864,7 @@ declare module 'stream' {
|
|
|
864
864
|
/**
|
|
865
865
|
* If `false` then the stream will automatically end the writable side when the
|
|
866
866
|
* readable side ends. Set initially by the `allowHalfOpen` constructor option,
|
|
867
|
-
* which defaults to `
|
|
867
|
+
* which defaults to `true`.
|
|
868
868
|
*
|
|
869
869
|
* This can be changed manually to change the half-open behavior of an existing`Duplex` stream instance, but must be changed before the `'end'` event is
|
|
870
870
|
* emitted.
|
|
@@ -912,6 +912,105 @@ declare module 'stream' {
|
|
|
912
912
|
end(chunk: any, encoding?: BufferEncoding, cb?: () => void): this;
|
|
913
913
|
cork(): void;
|
|
914
914
|
uncork(): void;
|
|
915
|
+
/**
|
|
916
|
+
* Event emitter
|
|
917
|
+
* The defined events on documents including:
|
|
918
|
+
* 1. close
|
|
919
|
+
* 2. data
|
|
920
|
+
* 3. drain
|
|
921
|
+
* 4. end
|
|
922
|
+
* 5. error
|
|
923
|
+
* 6. finish
|
|
924
|
+
* 7. pause
|
|
925
|
+
* 8. pipe
|
|
926
|
+
* 9. readable
|
|
927
|
+
* 10. resume
|
|
928
|
+
* 11. unpipe
|
|
929
|
+
*/
|
|
930
|
+
addListener(event: 'close', listener: () => void): this;
|
|
931
|
+
addListener(event: 'data', listener: (chunk: any) => void): this;
|
|
932
|
+
addListener(event: 'drain', listener: () => void): this;
|
|
933
|
+
addListener(event: 'end', listener: () => void): this;
|
|
934
|
+
addListener(event: 'error', listener: (err: Error) => void): this;
|
|
935
|
+
addListener(event: 'finish', listener: () => void): this;
|
|
936
|
+
addListener(event: 'pause', listener: () => void): this;
|
|
937
|
+
addListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
938
|
+
addListener(event: 'readable', listener: () => void): this;
|
|
939
|
+
addListener(event: 'resume', listener: () => void): this;
|
|
940
|
+
addListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
941
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
942
|
+
emit(event: 'close'): boolean;
|
|
943
|
+
emit(event: 'data', chunk: any): boolean;
|
|
944
|
+
emit(event: 'drain'): boolean;
|
|
945
|
+
emit(event: 'end'): boolean;
|
|
946
|
+
emit(event: 'error', err: Error): boolean;
|
|
947
|
+
emit(event: 'finish'): boolean;
|
|
948
|
+
emit(event: 'pause'): boolean;
|
|
949
|
+
emit(event: 'pipe', src: Readable): boolean;
|
|
950
|
+
emit(event: 'readable'): boolean;
|
|
951
|
+
emit(event: 'resume'): boolean;
|
|
952
|
+
emit(event: 'unpipe', src: Readable): boolean;
|
|
953
|
+
emit(event: string | symbol, ...args: any[]): boolean;
|
|
954
|
+
on(event: 'close', listener: () => void): this;
|
|
955
|
+
on(event: 'data', listener: (chunk: any) => void): this;
|
|
956
|
+
on(event: 'drain', listener: () => void): this;
|
|
957
|
+
on(event: 'end', listener: () => void): this;
|
|
958
|
+
on(event: 'error', listener: (err: Error) => void): this;
|
|
959
|
+
on(event: 'finish', listener: () => void): this;
|
|
960
|
+
on(event: 'pause', listener: () => void): this;
|
|
961
|
+
on(event: 'pipe', listener: (src: Readable) => void): this;
|
|
962
|
+
on(event: 'readable', listener: () => void): this;
|
|
963
|
+
on(event: 'resume', listener: () => void): this;
|
|
964
|
+
on(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
965
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
966
|
+
once(event: 'close', listener: () => void): this;
|
|
967
|
+
once(event: 'data', listener: (chunk: any) => void): this;
|
|
968
|
+
once(event: 'drain', listener: () => void): this;
|
|
969
|
+
once(event: 'end', listener: () => void): this;
|
|
970
|
+
once(event: 'error', listener: (err: Error) => void): this;
|
|
971
|
+
once(event: 'finish', listener: () => void): this;
|
|
972
|
+
once(event: 'pause', listener: () => void): this;
|
|
973
|
+
once(event: 'pipe', listener: (src: Readable) => void): this;
|
|
974
|
+
once(event: 'readable', listener: () => void): this;
|
|
975
|
+
once(event: 'resume', listener: () => void): this;
|
|
976
|
+
once(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
977
|
+
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
978
|
+
prependListener(event: 'close', listener: () => void): this;
|
|
979
|
+
prependListener(event: 'data', listener: (chunk: any) => void): this;
|
|
980
|
+
prependListener(event: 'drain', listener: () => void): this;
|
|
981
|
+
prependListener(event: 'end', listener: () => void): this;
|
|
982
|
+
prependListener(event: 'error', listener: (err: Error) => void): this;
|
|
983
|
+
prependListener(event: 'finish', listener: () => void): this;
|
|
984
|
+
prependListener(event: 'pause', listener: () => void): this;
|
|
985
|
+
prependListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
986
|
+
prependListener(event: 'readable', listener: () => void): this;
|
|
987
|
+
prependListener(event: 'resume', listener: () => void): this;
|
|
988
|
+
prependListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
989
|
+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
990
|
+
prependOnceListener(event: 'close', listener: () => void): this;
|
|
991
|
+
prependOnceListener(event: 'data', listener: (chunk: any) => void): this;
|
|
992
|
+
prependOnceListener(event: 'drain', listener: () => void): this;
|
|
993
|
+
prependOnceListener(event: 'end', listener: () => void): this;
|
|
994
|
+
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
|
995
|
+
prependOnceListener(event: 'finish', listener: () => void): this;
|
|
996
|
+
prependOnceListener(event: 'pause', listener: () => void): this;
|
|
997
|
+
prependOnceListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
998
|
+
prependOnceListener(event: 'readable', listener: () => void): this;
|
|
999
|
+
prependOnceListener(event: 'resume', listener: () => void): this;
|
|
1000
|
+
prependOnceListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
1001
|
+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
1002
|
+
removeListener(event: 'close', listener: () => void): this;
|
|
1003
|
+
removeListener(event: 'data', listener: (chunk: any) => void): this;
|
|
1004
|
+
removeListener(event: 'drain', listener: () => void): this;
|
|
1005
|
+
removeListener(event: 'end', listener: () => void): this;
|
|
1006
|
+
removeListener(event: 'error', listener: (err: Error) => void): this;
|
|
1007
|
+
removeListener(event: 'finish', listener: () => void): this;
|
|
1008
|
+
removeListener(event: 'pause', listener: () => void): this;
|
|
1009
|
+
removeListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
1010
|
+
removeListener(event: 'readable', listener: () => void): this;
|
|
1011
|
+
removeListener(event: 'resume', listener: () => void): this;
|
|
1012
|
+
removeListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
1013
|
+
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
915
1014
|
}
|
|
916
1015
|
type TransformCallback = (error?: Error | null, data?: any) => void;
|
|
917
1016
|
interface TransformOptions extends DuplexOptions {
|
|
@@ -953,18 +1052,21 @@ declare module 'stream' {
|
|
|
953
1052
|
*/
|
|
954
1053
|
class PassThrough extends Transform {}
|
|
955
1054
|
/**
|
|
1055
|
+
* A stream to attach a signal to.
|
|
1056
|
+
*
|
|
956
1057
|
* Attaches an AbortSignal to a readable or writeable stream. This lets code
|
|
957
1058
|
* control stream destruction using an `AbortController`.
|
|
958
1059
|
*
|
|
959
|
-
* Calling `abort` on the `AbortController` corresponding to the passed`AbortSignal` will behave the same way as calling `.destroy(new AbortError())`on the stream.
|
|
1060
|
+
* Calling `abort` on the `AbortController` corresponding to the passed`AbortSignal` will behave the same way as calling `.destroy(new AbortError())`on the stream, and `controller.error(new
|
|
1061
|
+
* AbortError())` for webstreams.
|
|
960
1062
|
*
|
|
961
1063
|
* ```js
|
|
962
|
-
* const fs = require('fs');
|
|
1064
|
+
* const fs = require('node:fs');
|
|
963
1065
|
*
|
|
964
1066
|
* const controller = new AbortController();
|
|
965
1067
|
* const read = addAbortSignal(
|
|
966
1068
|
* controller.signal,
|
|
967
|
-
* fs.createReadStream(('object.json'))
|
|
1069
|
+
* fs.createReadStream(('object.json')),
|
|
968
1070
|
* );
|
|
969
1071
|
* // Later, abort the operation closing the stream
|
|
970
1072
|
* controller.abort();
|
|
@@ -977,7 +1079,7 @@ declare module 'stream' {
|
|
|
977
1079
|
* setTimeout(() => controller.abort(), 10_000); // set a timeout
|
|
978
1080
|
* const stream = addAbortSignal(
|
|
979
1081
|
* controller.signal,
|
|
980
|
-
* fs.createReadStream(('object.json'))
|
|
1082
|
+
* fs.createReadStream(('object.json')),
|
|
981
1083
|
* );
|
|
982
1084
|
* (async () => {
|
|
983
1085
|
* try {
|
|
@@ -993,22 +1095,70 @@ declare module 'stream' {
|
|
|
993
1095
|
* }
|
|
994
1096
|
* })();
|
|
995
1097
|
* ```
|
|
1098
|
+
*
|
|
1099
|
+
* Or using an `AbortSignal` with a ReadableStream:
|
|
1100
|
+
*
|
|
1101
|
+
* ```js
|
|
1102
|
+
* const controller = new AbortController();
|
|
1103
|
+
* const rs = new ReadableStream({
|
|
1104
|
+
* start(controller) {
|
|
1105
|
+
* controller.enqueue('hello');
|
|
1106
|
+
* controller.enqueue('world');
|
|
1107
|
+
* controller.close();
|
|
1108
|
+
* },
|
|
1109
|
+
* });
|
|
1110
|
+
*
|
|
1111
|
+
* addAbortSignal(controller.signal, rs);
|
|
1112
|
+
*
|
|
1113
|
+
* finished(rs, (err) => {
|
|
1114
|
+
* if (err) {
|
|
1115
|
+
* if (err.name === 'AbortError') {
|
|
1116
|
+
* // The operation was cancelled
|
|
1117
|
+
* }
|
|
1118
|
+
* }
|
|
1119
|
+
* });
|
|
1120
|
+
*
|
|
1121
|
+
* const reader = rs.getReader();
|
|
1122
|
+
*
|
|
1123
|
+
* reader.read().then(({ value, done }) => {
|
|
1124
|
+
* console.log(value); // hello
|
|
1125
|
+
* console.log(done); // false
|
|
1126
|
+
* controller.abort();
|
|
1127
|
+
* });
|
|
1128
|
+
* ```
|
|
996
1129
|
* @since v15.4.0
|
|
997
1130
|
* @param signal A signal representing possible cancellation
|
|
998
1131
|
* @param stream a stream to attach a signal to
|
|
999
1132
|
*/
|
|
1000
1133
|
function addAbortSignal<T extends Stream>(signal: AbortSignal, stream: T): T;
|
|
1134
|
+
/**
|
|
1135
|
+
* Returns the default highWaterMark used by streams.
|
|
1136
|
+
* Defaults to `16384` (16 KiB), or `16` for `objectMode`.
|
|
1137
|
+
* @since v19.9.0
|
|
1138
|
+
* @param objectMode
|
|
1139
|
+
*/
|
|
1140
|
+
function getDefaultHighWaterMark(objectMode: boolean): number;
|
|
1141
|
+
/**
|
|
1142
|
+
* Sets the default highWaterMark used by streams.
|
|
1143
|
+
* @since v19.9.0
|
|
1144
|
+
* @param objectMode
|
|
1145
|
+
* @param value highWaterMark value
|
|
1146
|
+
*/
|
|
1147
|
+
function setDefaultHighWaterMark(objectMode: boolean, value: number): void;
|
|
1001
1148
|
interface FinishedOptions extends Abortable {
|
|
1002
1149
|
error?: boolean | undefined;
|
|
1003
1150
|
readable?: boolean | undefined;
|
|
1004
1151
|
writable?: boolean | undefined;
|
|
1005
1152
|
}
|
|
1006
1153
|
/**
|
|
1154
|
+
* A readable and/or writable stream/webstream.
|
|
1155
|
+
*
|
|
1007
1156
|
* A function to get notified when a stream is no longer readable, writable
|
|
1008
1157
|
* or has experienced an error or a premature close event.
|
|
1009
1158
|
*
|
|
1010
1159
|
* ```js
|
|
1011
|
-
* const { finished } = require('stream');
|
|
1160
|
+
* const { finished } = require('node:stream');
|
|
1161
|
+
* const fs = require('node:fs');
|
|
1012
1162
|
*
|
|
1013
1163
|
* const rs = fs.createReadStream('archive.tar');
|
|
1014
1164
|
*
|
|
@@ -1026,21 +1176,7 @@ declare module 'stream' {
|
|
|
1026
1176
|
* Especially useful in error handling scenarios where a stream is destroyed
|
|
1027
1177
|
* prematurely (like an aborted HTTP request), and will not emit `'end'`or `'finish'`.
|
|
1028
1178
|
*
|
|
1029
|
-
* The `finished` API provides promise version
|
|
1030
|
-
*
|
|
1031
|
-
* ```js
|
|
1032
|
-
* const { finished } = require('stream/promises');
|
|
1033
|
-
*
|
|
1034
|
-
* const rs = fs.createReadStream('archive.tar');
|
|
1035
|
-
*
|
|
1036
|
-
* async function run() {
|
|
1037
|
-
* await finished(rs);
|
|
1038
|
-
* console.log('Stream is done reading.');
|
|
1039
|
-
* }
|
|
1040
|
-
*
|
|
1041
|
-
* run().catch(console.error);
|
|
1042
|
-
* rs.resume(); // Drain the stream.
|
|
1043
|
-
* ```
|
|
1179
|
+
* The `finished` API provides `promise version`.
|
|
1044
1180
|
*
|
|
1045
1181
|
* `stream.finished()` leaves dangling event listeners (in particular`'error'`, `'end'`, `'finish'` and `'close'`) after `callback` has been
|
|
1046
1182
|
* invoked. The reason for this is so that unexpected `'error'` events (due to
|
|
@@ -1080,16 +1216,17 @@ declare module 'stream' {
|
|
|
1080
1216
|
: (err: NodeJS.ErrnoException | null) => void;
|
|
1081
1217
|
type PipelinePromise<S extends PipelineDestination<any, any>> = S extends PipelineDestinationPromiseFunction<any, infer P> ? Promise<P> : Promise<void>;
|
|
1082
1218
|
interface PipelineOptions {
|
|
1083
|
-
signal
|
|
1219
|
+
signal?: AbortSignal | undefined;
|
|
1220
|
+
end?: boolean | undefined;
|
|
1084
1221
|
}
|
|
1085
1222
|
/**
|
|
1086
1223
|
* A module method to pipe between streams and generators forwarding errors and
|
|
1087
1224
|
* properly cleaning up and provide a callback when the pipeline is complete.
|
|
1088
1225
|
*
|
|
1089
1226
|
* ```js
|
|
1090
|
-
* const { pipeline } = require('stream');
|
|
1091
|
-
* const fs = require('fs');
|
|
1092
|
-
* const zlib = require('zlib');
|
|
1227
|
+
* const { pipeline } = require('node:stream');
|
|
1228
|
+
* const fs = require('node:fs');
|
|
1229
|
+
* const zlib = require('node:zlib');
|
|
1093
1230
|
*
|
|
1094
1231
|
* // Use the pipeline API to easily pipe a series of streams
|
|
1095
1232
|
* // together and get notified when the pipeline is fully done.
|
|
@@ -1106,95 +1243,11 @@ declare module 'stream' {
|
|
|
1106
1243
|
* } else {
|
|
1107
1244
|
* console.log('Pipeline succeeded.');
|
|
1108
1245
|
* }
|
|
1109
|
-
* }
|
|
1246
|
+
* },
|
|
1110
1247
|
* );
|
|
1111
1248
|
* ```
|
|
1112
1249
|
*
|
|
1113
|
-
* The `pipeline` API provides a promise version
|
|
1114
|
-
* receive an options argument as the last parameter with a`signal` `AbortSignal` property. When the signal is aborted,`destroy` will be called on the underlying pipeline, with
|
|
1115
|
-
* an`AbortError`.
|
|
1116
|
-
*
|
|
1117
|
-
* ```js
|
|
1118
|
-
* const { pipeline } = require('stream/promises');
|
|
1119
|
-
*
|
|
1120
|
-
* async function run() {
|
|
1121
|
-
* await pipeline(
|
|
1122
|
-
* fs.createReadStream('archive.tar'),
|
|
1123
|
-
* zlib.createGzip(),
|
|
1124
|
-
* fs.createWriteStream('archive.tar.gz')
|
|
1125
|
-
* );
|
|
1126
|
-
* console.log('Pipeline succeeded.');
|
|
1127
|
-
* }
|
|
1128
|
-
*
|
|
1129
|
-
* run().catch(console.error);
|
|
1130
|
-
* ```
|
|
1131
|
-
*
|
|
1132
|
-
* To use an `AbortSignal`, pass it inside an options object,
|
|
1133
|
-
* as the last argument:
|
|
1134
|
-
*
|
|
1135
|
-
* ```js
|
|
1136
|
-
* const { pipeline } = require('stream/promises');
|
|
1137
|
-
*
|
|
1138
|
-
* async function run() {
|
|
1139
|
-
* const ac = new AbortController();
|
|
1140
|
-
* const signal = ac.signal;
|
|
1141
|
-
*
|
|
1142
|
-
* setTimeout(() => ac.abort(), 1);
|
|
1143
|
-
* await pipeline(
|
|
1144
|
-
* fs.createReadStream('archive.tar'),
|
|
1145
|
-
* zlib.createGzip(),
|
|
1146
|
-
* fs.createWriteStream('archive.tar.gz'),
|
|
1147
|
-
* { signal },
|
|
1148
|
-
* );
|
|
1149
|
-
* }
|
|
1150
|
-
*
|
|
1151
|
-
* run().catch(console.error); // AbortError
|
|
1152
|
-
* ```
|
|
1153
|
-
*
|
|
1154
|
-
* The `pipeline` API also supports async generators:
|
|
1155
|
-
*
|
|
1156
|
-
* ```js
|
|
1157
|
-
* const { pipeline } = require('stream/promises');
|
|
1158
|
-
* const fs = require('fs');
|
|
1159
|
-
*
|
|
1160
|
-
* async function run() {
|
|
1161
|
-
* await pipeline(
|
|
1162
|
-
* fs.createReadStream('lowercase.txt'),
|
|
1163
|
-
* async function* (source, { signal }) {
|
|
1164
|
-
* source.setEncoding('utf8'); // Work with strings rather than `Buffer`s.
|
|
1165
|
-
* for await (const chunk of source) {
|
|
1166
|
-
* yield await processChunk(chunk, { signal });
|
|
1167
|
-
* }
|
|
1168
|
-
* },
|
|
1169
|
-
* fs.createWriteStream('uppercase.txt')
|
|
1170
|
-
* );
|
|
1171
|
-
* console.log('Pipeline succeeded.');
|
|
1172
|
-
* }
|
|
1173
|
-
*
|
|
1174
|
-
* run().catch(console.error);
|
|
1175
|
-
* ```
|
|
1176
|
-
*
|
|
1177
|
-
* Remember to handle the `signal` argument passed into the async generator.
|
|
1178
|
-
* Especially in the case where the async generator is the source for the
|
|
1179
|
-
* pipeline (i.e. first argument) or the pipeline will never complete.
|
|
1180
|
-
*
|
|
1181
|
-
* ```js
|
|
1182
|
-
* const { pipeline } = require('stream/promises');
|
|
1183
|
-
* const fs = require('fs');
|
|
1184
|
-
*
|
|
1185
|
-
* async function run() {
|
|
1186
|
-
* await pipeline(
|
|
1187
|
-
* async function* ({ signal }) {
|
|
1188
|
-
* await someLongRunningfn({ signal });
|
|
1189
|
-
* yield 'asd';
|
|
1190
|
-
* },
|
|
1191
|
-
* fs.createWriteStream('uppercase.txt')
|
|
1192
|
-
* );
|
|
1193
|
-
* console.log('Pipeline succeeded.');
|
|
1194
|
-
* }
|
|
1195
|
-
*
|
|
1196
|
-
* run().catch(console.error);
|
|
1197
|
-
* ```
|
|
1250
|
+
* The `pipeline` API provides a `promise version`.
|
|
1198
1251
|
*
|
|
1199
1252
|
* `stream.pipeline()` will call `stream.destroy(err)` on all streams except:
|
|
1200
1253
|
*
|
|
@@ -1213,9 +1266,9 @@ declare module 'stream' {
|
|
|
1213
1266
|
* See the example below:
|
|
1214
1267
|
*
|
|
1215
1268
|
* ```js
|
|
1216
|
-
* const fs = require('fs');
|
|
1217
|
-
* const http = require('http');
|
|
1218
|
-
* const { pipeline } = require('stream');
|
|
1269
|
+
* const fs = require('node:fs');
|
|
1270
|
+
* const http = require('node:http');
|
|
1271
|
+
* const { pipeline } = require('node:stream');
|
|
1219
1272
|
*
|
|
1220
1273
|
* const server = http.createServer((req, res) => {
|
|
1221
1274
|
* const fileStream = fs.createReadStream('./fileNotExist.txt');
|
|
@@ -1316,19 +1369,18 @@ declare module 'stream' {
|
|
|
1316
1369
|
ref(): void;
|
|
1317
1370
|
unref(): void;
|
|
1318
1371
|
}
|
|
1319
|
-
|
|
1320
1372
|
/**
|
|
1321
1373
|
* Returns whether the stream has encountered an error.
|
|
1322
|
-
* @since v17.3.0
|
|
1374
|
+
* @since v17.3.0, v16.14.0
|
|
1375
|
+
* @experimental
|
|
1323
1376
|
*/
|
|
1324
1377
|
function isErrored(stream: Readable | Writable | NodeJS.ReadableStream | NodeJS.WritableStream): boolean;
|
|
1325
|
-
|
|
1326
1378
|
/**
|
|
1327
1379
|
* Returns whether the stream is readable.
|
|
1328
|
-
* @since v17.4.0
|
|
1380
|
+
* @since v17.4.0, v16.14.0
|
|
1381
|
+
* @experimental
|
|
1329
1382
|
*/
|
|
1330
1383
|
function isReadable(stream: Readable | NodeJS.ReadableStream): boolean;
|
|
1331
|
-
|
|
1332
1384
|
const promises: typeof streamPromises;
|
|
1333
1385
|
const consumers: typeof streamConsumers;
|
|
1334
1386
|
}
|