@rio-cloud/cdk-v2-constructs 8.2.0-alpha.0 → 8.2.1-alpha.0
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.
- package/.jsii +2 -2
- package/node_modules/@types/node/README.md +3 -3
- package/node_modules/@types/node/assert/strict.d.ts +105 -2
- package/node_modules/@types/node/assert.d.ts +211 -92
- package/node_modules/@types/node/async_hooks.d.ts +103 -19
- package/node_modules/@types/node/buffer.buffer.d.ts +472 -0
- package/node_modules/@types/node/buffer.d.ts +88 -516
- package/node_modules/@types/node/child_process.d.ts +167 -231
- package/node_modules/@types/node/cluster.d.ts +172 -26
- package/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
- package/node_modules/@types/node/console.d.ts +66 -28
- package/node_modules/@types/node/constants.d.ts +14 -12
- package/node_modules/@types/node/crypto.d.ts +1458 -497
- package/node_modules/@types/node/dgram.d.ts +44 -30
- package/node_modules/@types/node/diagnostics_channel.d.ts +389 -4
- package/node_modules/@types/node/dns/promises.d.ts +120 -42
- package/node_modules/@types/node/dns.d.ts +209 -95
- package/node_modules/@types/node/domain.d.ts +14 -18
- package/node_modules/@types/node/events.d.ts +245 -113
- package/node_modules/@types/node/fs/promises.d.ts +194 -96
- package/node_modules/@types/node/fs.d.ts +695 -270
- package/node_modules/@types/node/globals.d.ts +97 -308
- package/node_modules/@types/node/globals.typedarray.d.ts +41 -0
- package/node_modules/@types/node/http.d.ts +363 -97
- package/node_modules/@types/node/http2.d.ts +684 -231
- package/node_modules/@types/node/https.d.ts +122 -87
- package/node_modules/@types/node/index.d.ts +24 -11
- package/node_modules/@types/node/inspector.d.ts +220 -2690
- package/node_modules/@types/node/inspector.generated.d.ts +4239 -0
- package/node_modules/@types/node/module.d.ts +705 -149
- package/node_modules/@types/node/net.d.ts +178 -54
- package/node_modules/@types/node/os.d.ts +47 -17
- package/node_modules/@types/node/package.json +22 -97
- package/node_modules/@types/node/path.d.ts +12 -3
- package/node_modules/@types/node/perf_hooks.d.ts +500 -97
- package/node_modules/@types/node/process.d.ts +657 -87
- package/node_modules/@types/node/punycode.d.ts +5 -5
- package/node_modules/@types/node/querystring.d.ts +24 -13
- package/node_modules/@types/node/readline/promises.d.ts +25 -14
- package/node_modules/@types/node/readline.d.ts +102 -41
- package/node_modules/@types/node/repl.d.ts +38 -30
- package/node_modules/@types/node/sea.d.ts +162 -0
- package/node_modules/@types/node/sqlite.d.ts +1040 -0
- package/node_modules/@types/node/stream/consumers.d.ts +33 -7
- package/node_modules/@types/node/stream/promises.d.ts +8 -1
- package/node_modules/@types/node/stream/web.d.ts +251 -28
- package/node_modules/@types/node/stream.d.ts +1060 -1055
- package/node_modules/@types/node/string_decoder.d.ts +8 -8
- package/node_modules/@types/node/test.d.ts +2133 -1166
- package/node_modules/@types/node/timers/promises.d.ts +31 -16
- package/node_modules/@types/node/timers.d.ts +159 -114
- package/node_modules/@types/node/tls.d.ts +232 -163
- package/node_modules/@types/node/trace_events.d.ts +43 -28
- package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +468 -0
- package/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +71 -0
- package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +36 -0
- package/node_modules/@types/node/ts5.6/index.d.ts +103 -0
- package/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +72 -0
- package/node_modules/@types/node/ts5.7/index.d.ts +103 -0
- package/node_modules/@types/node/tty.d.ts +9 -9
- package/node_modules/@types/node/url.d.ts +236 -84
- package/node_modules/@types/node/util.d.ts +562 -412
- package/node_modules/@types/node/v8.d.ts +368 -21
- package/node_modules/@types/node/vm.d.ts +443 -149
- package/node_modules/@types/node/wasi.d.ts +62 -18
- package/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
- package/node_modules/@types/node/web-globals/crypto.d.ts +32 -0
- package/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
- package/node_modules/@types/node/web-globals/events.d.ts +97 -0
- package/node_modules/@types/node/web-globals/fetch.d.ts +62 -0
- package/node_modules/@types/node/web-globals/navigator.d.ts +25 -0
- package/node_modules/@types/node/web-globals/storage.d.ts +24 -0
- package/node_modules/@types/node/web-globals/streams.d.ts +22 -0
- package/node_modules/@types/node/worker_threads.d.ts +310 -107
- package/node_modules/@types/node/zlib.d.ts +301 -73
- package/node_modules/undici-types/LICENSE +21 -0
- package/node_modules/undici-types/agent.d.ts +13 -12
- package/node_modules/undici-types/api.d.ts +26 -26
- package/node_modules/undici-types/balanced-pool.d.ts +19 -7
- package/node_modules/undici-types/cache-interceptor.d.ts +173 -0
- package/node_modules/undici-types/client-stats.d.ts +15 -0
- package/node_modules/undici-types/client.d.ts +26 -15
- package/node_modules/undici-types/connector.d.ts +2 -2
- package/node_modules/undici-types/cookies.d.ts +2 -0
- package/node_modules/undici-types/diagnostics-channel.d.ts +19 -12
- package/node_modules/undici-types/dispatcher.d.ts +148 -113
- package/node_modules/undici-types/env-http-proxy-agent.d.ts +22 -0
- package/node_modules/undici-types/errors.d.ts +79 -46
- package/node_modules/undici-types/eventsource.d.ts +66 -0
- package/node_modules/undici-types/fetch.d.ts +41 -39
- package/node_modules/undici-types/formdata.d.ts +8 -8
- package/node_modules/undici-types/global-dispatcher.d.ts +4 -4
- package/node_modules/undici-types/global-origin.d.ts +5 -5
- package/node_modules/undici-types/h2c-client.d.ts +73 -0
- package/node_modules/undici-types/handlers.d.ts +11 -5
- package/node_modules/undici-types/header.d.ts +157 -1
- package/node_modules/undici-types/index.d.ts +68 -43
- package/node_modules/undici-types/interceptors.d.ts +71 -3
- package/node_modules/undici-types/mock-agent.d.ts +36 -18
- package/node_modules/undici-types/mock-call-history.d.ts +111 -0
- package/node_modules/undici-types/mock-client.d.ts +6 -4
- package/node_modules/undici-types/mock-errors.d.ts +3 -3
- package/node_modules/undici-types/mock-interceptor.d.ts +24 -23
- package/node_modules/undici-types/mock-pool.d.ts +6 -4
- package/node_modules/undici-types/package.json +1 -1
- package/node_modules/undici-types/patch.d.ts +0 -42
- package/node_modules/undici-types/pool-stats.d.ts +8 -8
- package/node_modules/undici-types/pool.d.ts +21 -8
- package/node_modules/undici-types/proxy-agent.d.ts +5 -6
- package/node_modules/undici-types/readable.d.ts +24 -17
- package/node_modules/undici-types/retry-agent.d.ts +8 -0
- package/node_modules/undici-types/retry-handler.d.ts +125 -0
- package/node_modules/undici-types/round-robin-pool.d.ts +41 -0
- package/node_modules/undici-types/snapshot-agent.d.ts +109 -0
- package/node_modules/undici-types/util.d.ts +18 -0
- package/node_modules/undici-types/utility.d.ts +7 -0
- package/node_modules/undici-types/webidl.d.ts +157 -36
- package/node_modules/undici-types/websocket.d.ts +67 -12
- package/package.json +9 -60
- package/version.json +1 -1
- package/node_modules/@types/node/dom-events.d.ts +0 -122
- package/node_modules/@types/node/globals.global.d.ts +0 -1
- package/node_modules/@types/node/ts4.8/assert/strict.d.ts +0 -8
- package/node_modules/@types/node/ts4.8/assert.d.ts +0 -996
- package/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -539
- package/node_modules/@types/node/ts4.8/buffer.d.ts +0 -2362
- package/node_modules/@types/node/ts4.8/child_process.d.ts +0 -1540
- package/node_modules/@types/node/ts4.8/cluster.d.ts +0 -432
- package/node_modules/@types/node/ts4.8/console.d.ts +0 -415
- package/node_modules/@types/node/ts4.8/constants.d.ts +0 -19
- package/node_modules/@types/node/ts4.8/crypto.d.ts +0 -4455
- package/node_modules/@types/node/ts4.8/dgram.d.ts +0 -586
- package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +0 -191
- package/node_modules/@types/node/ts4.8/dns/promises.d.ts +0 -425
- package/node_modules/@types/node/ts4.8/dns.d.ts +0 -809
- package/node_modules/@types/node/ts4.8/dom-events.d.ts +0 -122
- package/node_modules/@types/node/ts4.8/domain.d.ts +0 -170
- package/node_modules/@types/node/ts4.8/events.d.ts +0 -796
- package/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -1232
- package/node_modules/@types/node/ts4.8/fs.d.ts +0 -4289
- package/node_modules/@types/node/ts4.8/globals.d.ts +0 -381
- package/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
- package/node_modules/@types/node/ts4.8/http.d.ts +0 -1888
- package/node_modules/@types/node/ts4.8/http2.d.ts +0 -2382
- package/node_modules/@types/node/ts4.8/https.d.ts +0 -550
- package/node_modules/@types/node/ts4.8/index.d.ts +0 -88
- package/node_modules/@types/node/ts4.8/inspector.d.ts +0 -2747
- package/node_modules/@types/node/ts4.8/module.d.ts +0 -287
- package/node_modules/@types/node/ts4.8/net.d.ts +0 -949
- package/node_modules/@types/node/ts4.8/os.d.ts +0 -477
- package/node_modules/@types/node/ts4.8/path.d.ts +0 -191
- package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -639
- package/node_modules/@types/node/ts4.8/process.d.ts +0 -1532
- package/node_modules/@types/node/ts4.8/punycode.d.ts +0 -117
- package/node_modules/@types/node/ts4.8/querystring.d.ts +0 -141
- package/node_modules/@types/node/ts4.8/readline/promises.d.ts +0 -150
- package/node_modules/@types/node/ts4.8/readline.d.ts +0 -539
- package/node_modules/@types/node/ts4.8/repl.d.ts +0 -430
- package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +0 -12
- package/node_modules/@types/node/ts4.8/stream/promises.d.ts +0 -83
- package/node_modules/@types/node/ts4.8/stream/web.d.ts +0 -350
- package/node_modules/@types/node/ts4.8/stream.d.ts +0 -1701
- package/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -67
- package/node_modules/@types/node/ts4.8/test.d.ts +0 -1382
- package/node_modules/@types/node/ts4.8/timers/promises.d.ts +0 -93
- package/node_modules/@types/node/ts4.8/timers.d.ts +0 -240
- package/node_modules/@types/node/ts4.8/tls.d.ts +0 -1210
- package/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -182
- package/node_modules/@types/node/ts4.8/tty.d.ts +0 -208
- package/node_modules/@types/node/ts4.8/url.d.ts +0 -927
- package/node_modules/@types/node/ts4.8/util.d.ts +0 -2186
- package/node_modules/@types/node/ts4.8/v8.d.ts +0 -635
- package/node_modules/@types/node/ts4.8/vm.d.ts +0 -901
- package/node_modules/@types/node/ts4.8/wasi.d.ts +0 -158
- package/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -691
- package/node_modules/@types/node/ts4.8/zlib.d.ts +0 -517
- package/node_modules/argparse/CHANGELOG.md +0 -216
- package/node_modules/undici-types/file.d.ts +0 -39
- package/node_modules/undici-types/filereader.d.ts +0 -54
|
@@ -2,30 +2,30 @@
|
|
|
2
2
|
* A stream is an abstract interface for working with streaming data in Node.js.
|
|
3
3
|
* The `node:stream` module provides an API for implementing the stream interface.
|
|
4
4
|
*
|
|
5
|
-
* There are many stream objects provided by Node.js. For instance, a
|
|
5
|
+
* There are many stream objects provided by Node.js. For instance, a [request to an HTTP server](https://nodejs.org/docs/latest-v24.x/api/http.html#class-httpincomingmessage)
|
|
6
|
+
* and [`process.stdout`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstdout) are both stream instances.
|
|
6
7
|
*
|
|
7
|
-
* Streams can be readable, writable, or both. All streams are instances of `EventEmitter
|
|
8
|
+
* Streams can be readable, writable, or both. All streams are instances of [`EventEmitter`](https://nodejs.org/docs/latest-v24.x/api/events.html#class-eventemitter).
|
|
8
9
|
*
|
|
9
10
|
* To access the `node:stream` module:
|
|
10
11
|
*
|
|
11
12
|
* ```js
|
|
12
|
-
*
|
|
13
|
+
* import stream from 'node:stream';
|
|
13
14
|
* ```
|
|
14
15
|
*
|
|
15
16
|
* The `node:stream` module is useful for creating new types of stream instances.
|
|
16
17
|
* It is usually not necessary to use the `node:stream` module to consume streams.
|
|
17
|
-
* @see [source](https://github.com/nodejs/node/blob/
|
|
18
|
+
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/stream.js)
|
|
18
19
|
*/
|
|
19
20
|
declare module "stream" {
|
|
20
21
|
import { Abortable, EventEmitter } from "node:events";
|
|
21
22
|
import { Blob as NodeBlob } from "node:buffer";
|
|
22
23
|
import * as streamPromises from "node:stream/promises";
|
|
23
|
-
import * as streamConsumers from "node:stream/consumers";
|
|
24
24
|
import * as streamWeb from "node:stream/web";
|
|
25
25
|
|
|
26
26
|
type ComposeFnParam = (source: any) => void;
|
|
27
27
|
|
|
28
|
-
class
|
|
28
|
+
class Stream extends EventEmitter {
|
|
29
29
|
pipe<T extends NodeJS.WritableStream>(
|
|
30
30
|
destination: T,
|
|
31
31
|
options?: {
|
|
@@ -37,1003 +37,1031 @@ declare module "stream" {
|
|
|
37
37
|
options?: { signal: AbortSignal },
|
|
38
38
|
): T;
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
import ReadableOptions = internal.ReadableOptions;
|
|
43
|
-
interface ArrayOptions {
|
|
44
|
-
/** the maximum concurrent invocations of `fn` to call on the stream at once. **Default: 1**. */
|
|
45
|
-
concurrency?: number;
|
|
46
|
-
/** allows destroying the stream if the signal is aborted. */
|
|
47
|
-
signal?: AbortSignal;
|
|
40
|
+
namespace Stream {
|
|
41
|
+
export { Stream, streamPromises as promises };
|
|
48
42
|
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* A utility method for creating Readable Streams out of iterators.
|
|
52
|
-
*/
|
|
53
|
-
static from(iterable: Iterable<any> | AsyncIterable<any>, options?: ReadableOptions): Readable;
|
|
54
|
-
/**
|
|
55
|
-
* Returns whether the stream has been read from or cancelled.
|
|
56
|
-
* @since v16.8.0
|
|
57
|
-
*/
|
|
58
|
-
static isDisturbed(stream: Readable | NodeJS.ReadableStream): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Returns whether the stream was destroyed or errored before emitting `'end'`.
|
|
61
|
-
* @since v16.8.0
|
|
62
|
-
* @experimental
|
|
63
|
-
*/
|
|
64
|
-
readonly readableAborted: boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Is `true` if it is safe to call `readable.read()`, which means
|
|
67
|
-
* the stream has not been destroyed or emitted `'error'` or `'end'`.
|
|
68
|
-
* @since v11.4.0
|
|
69
|
-
*/
|
|
70
|
-
readable: boolean;
|
|
71
|
-
/**
|
|
72
|
-
* Returns whether `'data'` has been emitted.
|
|
73
|
-
* @since v16.7.0, v14.18.0
|
|
74
|
-
* @experimental
|
|
75
|
-
*/
|
|
76
|
-
readonly readableDidRead: boolean;
|
|
77
|
-
/**
|
|
78
|
-
* Getter for the property `encoding` of a given `Readable` stream. The `encoding`property can be set using the `readable.setEncoding()` method.
|
|
79
|
-
* @since v12.7.0
|
|
80
|
-
*/
|
|
81
|
-
readonly readableEncoding: BufferEncoding | null;
|
|
82
|
-
/**
|
|
83
|
-
* Becomes `true` when `'end'` event is emitted.
|
|
84
|
-
* @since v12.9.0
|
|
85
|
-
*/
|
|
86
|
-
readonly readableEnded: boolean;
|
|
87
|
-
/**
|
|
88
|
-
* This property reflects the current state of a `Readable` stream as described
|
|
89
|
-
* in the `Three states` section.
|
|
90
|
-
* @since v9.4.0
|
|
91
|
-
*/
|
|
92
|
-
readonly readableFlowing: boolean | null;
|
|
93
|
-
/**
|
|
94
|
-
* Returns the value of `highWaterMark` passed when creating this `Readable`.
|
|
95
|
-
* @since v9.3.0
|
|
96
|
-
*/
|
|
97
|
-
readonly readableHighWaterMark: number;
|
|
98
|
-
/**
|
|
99
|
-
* This property contains the number of bytes (or objects) in the queue
|
|
100
|
-
* ready to be read. The value provides introspection data regarding
|
|
101
|
-
* the status of the `highWaterMark`.
|
|
102
|
-
* @since v9.4.0
|
|
103
|
-
*/
|
|
104
|
-
readonly readableLength: number;
|
|
105
|
-
/**
|
|
106
|
-
* Getter for the property `objectMode` of a given `Readable` stream.
|
|
107
|
-
* @since v12.3.0
|
|
108
|
-
*/
|
|
109
|
-
readonly readableObjectMode: boolean;
|
|
110
|
-
/**
|
|
111
|
-
* Is `true` after `readable.destroy()` has been called.
|
|
112
|
-
* @since v8.0.0
|
|
113
|
-
*/
|
|
114
|
-
destroyed: boolean;
|
|
115
|
-
/**
|
|
116
|
-
* Is `true` after `'close'` has been emitted.
|
|
117
|
-
* @since v18.0.0
|
|
118
|
-
*/
|
|
119
|
-
readonly closed: boolean;
|
|
120
|
-
/**
|
|
121
|
-
* Returns error if the stream has been destroyed with an error.
|
|
122
|
-
* @since v18.0.0
|
|
123
|
-
*/
|
|
124
|
-
readonly errored: Error | null;
|
|
125
|
-
constructor(opts?: ReadableOptions);
|
|
126
|
-
_construct?(callback: (error?: Error | null) => void): void;
|
|
127
|
-
_read(size: number): void;
|
|
128
|
-
/**
|
|
129
|
-
* The `readable.read()` method reads data out of the internal buffer and
|
|
130
|
-
* returns it. If no data is available to be read, `null` is returned. By default,
|
|
131
|
-
* the data is returned as a `Buffer` object unless an encoding has been
|
|
132
|
-
* specified using the `readable.setEncoding()` method or the stream is operating
|
|
133
|
-
* in object mode.
|
|
134
|
-
*
|
|
135
|
-
* The optional `size` argument specifies a specific number of bytes to read. If`size` bytes are not available to be read, `null` will be returned _unless_the stream has ended, in which
|
|
136
|
-
* case all of the data remaining in the internal
|
|
137
|
-
* buffer will be returned.
|
|
138
|
-
*
|
|
139
|
-
* If the `size` argument is not specified, all of the data contained in the
|
|
140
|
-
* internal buffer will be returned.
|
|
141
|
-
*
|
|
142
|
-
* The `size` argument must be less than or equal to 1 GiB.
|
|
143
|
-
*
|
|
144
|
-
* The `readable.read()` method should only be called on `Readable` streams
|
|
145
|
-
* operating in paused mode. In flowing mode, `readable.read()` is called
|
|
146
|
-
* automatically until the internal buffer is fully drained.
|
|
147
|
-
*
|
|
148
|
-
* ```js
|
|
149
|
-
* const readable = getReadableStreamSomehow();
|
|
150
|
-
*
|
|
151
|
-
* // 'readable' may be triggered multiple times as data is buffered in
|
|
152
|
-
* readable.on('readable', () => {
|
|
153
|
-
* let chunk;
|
|
154
|
-
* console.log('Stream is readable (new data received in buffer)');
|
|
155
|
-
* // Use a loop to make sure we read all currently available data
|
|
156
|
-
* while (null !== (chunk = readable.read())) {
|
|
157
|
-
* console.log(`Read ${chunk.length} bytes of data...`);
|
|
158
|
-
* }
|
|
159
|
-
* });
|
|
160
|
-
*
|
|
161
|
-
* // 'end' will be triggered once when there is no more data available
|
|
162
|
-
* readable.on('end', () => {
|
|
163
|
-
* console.log('Reached end of stream.');
|
|
164
|
-
* });
|
|
165
|
-
* ```
|
|
166
|
-
*
|
|
167
|
-
* Each call to `readable.read()` returns a chunk of data, or `null`. The chunks
|
|
168
|
-
* are not concatenated. A `while` loop is necessary to consume all data
|
|
169
|
-
* currently in the buffer. When reading a large file `.read()` may return `null`,
|
|
170
|
-
* having consumed all buffered content so far, but there is still more data to
|
|
171
|
-
* come not yet buffered. In this case a new `'readable'` event will be emitted
|
|
172
|
-
* when there is more data in the buffer. Finally the `'end'` event will be
|
|
173
|
-
* emitted when there is no more data to come.
|
|
174
|
-
*
|
|
175
|
-
* Therefore to read a file's whole contents from a `readable`, it is necessary
|
|
176
|
-
* to collect chunks across multiple `'readable'` events:
|
|
177
|
-
*
|
|
178
|
-
* ```js
|
|
179
|
-
* const chunks = [];
|
|
180
|
-
*
|
|
181
|
-
* readable.on('readable', () => {
|
|
182
|
-
* let chunk;
|
|
183
|
-
* while (null !== (chunk = readable.read())) {
|
|
184
|
-
* chunks.push(chunk);
|
|
185
|
-
* }
|
|
186
|
-
* });
|
|
187
|
-
*
|
|
188
|
-
* readable.on('end', () => {
|
|
189
|
-
* const content = chunks.join('');
|
|
190
|
-
* });
|
|
191
|
-
* ```
|
|
192
|
-
*
|
|
193
|
-
* A `Readable` stream in object mode will always return a single item from
|
|
194
|
-
* a call to `readable.read(size)`, regardless of the value of the`size` argument.
|
|
195
|
-
*
|
|
196
|
-
* If the `readable.read()` method returns a chunk of data, a `'data'` event will
|
|
197
|
-
* also be emitted.
|
|
198
|
-
*
|
|
199
|
-
* Calling {@link read} after the `'end'` event has
|
|
200
|
-
* been emitted will return `null`. No runtime error will be raised.
|
|
201
|
-
* @since v0.9.4
|
|
202
|
-
* @param size Optional argument to specify how much data to read.
|
|
203
|
-
*/
|
|
204
|
-
read(size?: number): any;
|
|
205
|
-
/**
|
|
206
|
-
* The `readable.setEncoding()` method sets the character encoding for
|
|
207
|
-
* data read from the `Readable` stream.
|
|
208
|
-
*
|
|
209
|
-
* By default, no encoding is assigned and stream data will be returned as`Buffer` objects. Setting an encoding causes the stream data
|
|
210
|
-
* to be returned as strings of the specified encoding rather than as `Buffer`objects. For instance, calling `readable.setEncoding('utf8')` will cause the
|
|
211
|
-
* output data to be interpreted as UTF-8 data, and passed as strings. Calling`readable.setEncoding('hex')` will cause the data to be encoded in hexadecimal
|
|
212
|
-
* string format.
|
|
213
|
-
*
|
|
214
|
-
* The `Readable` stream will properly handle multi-byte characters delivered
|
|
215
|
-
* through the stream that would otherwise become improperly decoded if simply
|
|
216
|
-
* pulled from the stream as `Buffer` objects.
|
|
217
|
-
*
|
|
218
|
-
* ```js
|
|
219
|
-
* const readable = getReadableStreamSomehow();
|
|
220
|
-
* readable.setEncoding('utf8');
|
|
221
|
-
* readable.on('data', (chunk) => {
|
|
222
|
-
* assert.equal(typeof chunk, 'string');
|
|
223
|
-
* console.log('Got %d characters of string data:', chunk.length);
|
|
224
|
-
* });
|
|
225
|
-
* ```
|
|
226
|
-
* @since v0.9.4
|
|
227
|
-
* @param encoding The encoding to use.
|
|
228
|
-
*/
|
|
229
|
-
setEncoding(encoding: BufferEncoding): this;
|
|
230
|
-
/**
|
|
231
|
-
* The `readable.pause()` method will cause a stream in flowing mode to stop
|
|
232
|
-
* emitting `'data'` events, switching out of flowing mode. Any data that
|
|
233
|
-
* becomes available will remain in the internal buffer.
|
|
234
|
-
*
|
|
235
|
-
* ```js
|
|
236
|
-
* const readable = getReadableStreamSomehow();
|
|
237
|
-
* readable.on('data', (chunk) => {
|
|
238
|
-
* console.log(`Received ${chunk.length} bytes of data.`);
|
|
239
|
-
* readable.pause();
|
|
240
|
-
* console.log('There will be no additional data for 1 second.');
|
|
241
|
-
* setTimeout(() => {
|
|
242
|
-
* console.log('Now data will start flowing again.');
|
|
243
|
-
* readable.resume();
|
|
244
|
-
* }, 1000);
|
|
245
|
-
* });
|
|
246
|
-
* ```
|
|
247
|
-
*
|
|
248
|
-
* The `readable.pause()` method has no effect if there is a `'readable'`event listener.
|
|
249
|
-
* @since v0.9.4
|
|
250
|
-
*/
|
|
251
|
-
pause(): this;
|
|
252
|
-
/**
|
|
253
|
-
* The `readable.resume()` method causes an explicitly paused `Readable` stream to
|
|
254
|
-
* resume emitting `'data'` events, switching the stream into flowing mode.
|
|
255
|
-
*
|
|
256
|
-
* The `readable.resume()` method can be used to fully consume the data from a
|
|
257
|
-
* stream without actually processing any of that data:
|
|
258
|
-
*
|
|
259
|
-
* ```js
|
|
260
|
-
* getReadableStreamSomehow()
|
|
261
|
-
* .resume()
|
|
262
|
-
* .on('end', () => {
|
|
263
|
-
* console.log('Reached the end, but did not read anything.');
|
|
264
|
-
* });
|
|
265
|
-
* ```
|
|
266
|
-
*
|
|
267
|
-
* The `readable.resume()` method has no effect if there is a `'readable'`event listener.
|
|
268
|
-
* @since v0.9.4
|
|
269
|
-
*/
|
|
270
|
-
resume(): this;
|
|
271
|
-
/**
|
|
272
|
-
* The `readable.isPaused()` method returns the current operating state of the`Readable`. This is used primarily by the mechanism that underlies the`readable.pipe()` method. In most
|
|
273
|
-
* typical cases, there will be no reason to
|
|
274
|
-
* use this method directly.
|
|
275
|
-
*
|
|
276
|
-
* ```js
|
|
277
|
-
* const readable = new stream.Readable();
|
|
278
|
-
*
|
|
279
|
-
* readable.isPaused(); // === false
|
|
280
|
-
* readable.pause();
|
|
281
|
-
* readable.isPaused(); // === true
|
|
282
|
-
* readable.resume();
|
|
283
|
-
* readable.isPaused(); // === false
|
|
284
|
-
* ```
|
|
285
|
-
* @since v0.11.14
|
|
286
|
-
*/
|
|
287
|
-
isPaused(): boolean;
|
|
288
|
-
/**
|
|
289
|
-
* The `readable.unpipe()` method detaches a `Writable` stream previously attached
|
|
290
|
-
* using the {@link pipe} method.
|
|
291
|
-
*
|
|
292
|
-
* If the `destination` is not specified, then _all_ pipes are detached.
|
|
293
|
-
*
|
|
294
|
-
* If the `destination` is specified, but no pipe is set up for it, then
|
|
295
|
-
* the method does nothing.
|
|
296
|
-
*
|
|
297
|
-
* ```js
|
|
298
|
-
* const fs = require('node:fs');
|
|
299
|
-
* const readable = getReadableStreamSomehow();
|
|
300
|
-
* const writable = fs.createWriteStream('file.txt');
|
|
301
|
-
* // All the data from readable goes into 'file.txt',
|
|
302
|
-
* // but only for the first second.
|
|
303
|
-
* readable.pipe(writable);
|
|
304
|
-
* setTimeout(() => {
|
|
305
|
-
* console.log('Stop writing to file.txt.');
|
|
306
|
-
* readable.unpipe(writable);
|
|
307
|
-
* console.log('Manually close the file stream.');
|
|
308
|
-
* writable.end();
|
|
309
|
-
* }, 1000);
|
|
310
|
-
* ```
|
|
311
|
-
* @since v0.9.4
|
|
312
|
-
* @param destination Optional specific stream to unpipe
|
|
313
|
-
*/
|
|
314
|
-
unpipe(destination?: NodeJS.WritableStream): this;
|
|
315
|
-
/**
|
|
316
|
-
* Passing `chunk` as `null` signals the end of the stream (EOF) and behaves the
|
|
317
|
-
* same as `readable.push(null)`, after which no more data can be written. The EOF
|
|
318
|
-
* signal is put at the end of the buffer and any buffered data will still be
|
|
319
|
-
* flushed.
|
|
320
|
-
*
|
|
321
|
-
* The `readable.unshift()` method pushes a chunk of data back into the internal
|
|
322
|
-
* buffer. This is useful in certain situations where a stream is being consumed by
|
|
323
|
-
* code that needs to "un-consume" some amount of data that it has optimistically
|
|
324
|
-
* pulled out of the source, so that the data can be passed on to some other party.
|
|
325
|
-
*
|
|
326
|
-
* The `stream.unshift(chunk)` method cannot be called after the `'end'` event
|
|
327
|
-
* has been emitted or a runtime error will be thrown.
|
|
328
|
-
*
|
|
329
|
-
* Developers using `stream.unshift()` often should consider switching to
|
|
330
|
-
* use of a `Transform` stream instead. See the `API for stream implementers` section for more information.
|
|
331
|
-
*
|
|
332
|
-
* ```js
|
|
333
|
-
* // Pull off a header delimited by \n\n.
|
|
334
|
-
* // Use unshift() if we get too much.
|
|
335
|
-
* // Call the callback with (error, header, stream).
|
|
336
|
-
* const { StringDecoder } = require('node:string_decoder');
|
|
337
|
-
* function parseHeader(stream, callback) {
|
|
338
|
-
* stream.on('error', callback);
|
|
339
|
-
* stream.on('readable', onReadable);
|
|
340
|
-
* const decoder = new StringDecoder('utf8');
|
|
341
|
-
* let header = '';
|
|
342
|
-
* function onReadable() {
|
|
343
|
-
* let chunk;
|
|
344
|
-
* while (null !== (chunk = stream.read())) {
|
|
345
|
-
* const str = decoder.write(chunk);
|
|
346
|
-
* if (str.includes('\n\n')) {
|
|
347
|
-
* // Found the header boundary.
|
|
348
|
-
* const split = str.split(/\n\n/);
|
|
349
|
-
* header += split.shift();
|
|
350
|
-
* const remaining = split.join('\n\n');
|
|
351
|
-
* const buf = Buffer.from(remaining, 'utf8');
|
|
352
|
-
* stream.removeListener('error', callback);
|
|
353
|
-
* // Remove the 'readable' listener before unshifting.
|
|
354
|
-
* stream.removeListener('readable', onReadable);
|
|
355
|
-
* if (buf.length)
|
|
356
|
-
* stream.unshift(buf);
|
|
357
|
-
* // Now the body of the message can be read from the stream.
|
|
358
|
-
* callback(null, header, stream);
|
|
359
|
-
* return;
|
|
360
|
-
* }
|
|
361
|
-
* // Still reading the header.
|
|
362
|
-
* header += str;
|
|
363
|
-
* }
|
|
364
|
-
* }
|
|
365
|
-
* }
|
|
366
|
-
* ```
|
|
367
|
-
*
|
|
368
|
-
* Unlike {@link push}, `stream.unshift(chunk)` will not
|
|
369
|
-
* end the reading process by resetting the internal reading state of the stream.
|
|
370
|
-
* This can cause unexpected results if `readable.unshift()` is called during a
|
|
371
|
-
* read (i.e. from within a {@link _read} implementation on a
|
|
372
|
-
* custom stream). Following the call to `readable.unshift()` with an immediate {@link push} will reset the reading state appropriately,
|
|
373
|
-
* however it is best to simply avoid calling `readable.unshift()` while in the
|
|
374
|
-
* process of performing a read.
|
|
375
|
-
* @since v0.9.11
|
|
376
|
-
* @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
|
|
377
|
-
* streams, `chunk` may be any JavaScript value.
|
|
378
|
-
* @param encoding Encoding of string chunks. Must be a valid `Buffer` encoding, such as `'utf8'` or `'ascii'`.
|
|
379
|
-
*/
|
|
380
|
-
unshift(chunk: any, encoding?: BufferEncoding): void;
|
|
381
|
-
/**
|
|
382
|
-
* 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
|
|
383
|
-
* information.)
|
|
384
|
-
*
|
|
385
|
-
* 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`
|
|
386
|
-
* stream that uses
|
|
387
|
-
* the old stream as its data source.
|
|
388
|
-
*
|
|
389
|
-
* It will rarely be necessary to use `readable.wrap()` but the method has been
|
|
390
|
-
* provided as a convenience for interacting with older Node.js applications and
|
|
391
|
-
* libraries.
|
|
392
|
-
*
|
|
393
|
-
* ```js
|
|
394
|
-
* const { OldReader } = require('./old-api-module.js');
|
|
395
|
-
* const { Readable } = require('node:stream');
|
|
396
|
-
* const oreader = new OldReader();
|
|
397
|
-
* const myReader = new Readable().wrap(oreader);
|
|
398
|
-
*
|
|
399
|
-
* myReader.on('readable', () => {
|
|
400
|
-
* myReader.read(); // etc.
|
|
401
|
-
* });
|
|
402
|
-
* ```
|
|
403
|
-
* @since v0.9.4
|
|
404
|
-
* @param stream An "old style" readable stream
|
|
405
|
-
*/
|
|
406
|
-
wrap(stream: NodeJS.ReadableStream): this;
|
|
407
|
-
push(chunk: any, encoding?: BufferEncoding): boolean;
|
|
408
|
-
/**
|
|
409
|
-
* The iterator created by this method gives users the option to cancel the destruction
|
|
410
|
-
* of the stream if the `for await...of` loop is exited by `return`, `break`, or `throw`,
|
|
411
|
-
* or if the iterator should destroy the stream if the stream emitted an error during iteration.
|
|
412
|
-
* @since v16.3.0
|
|
413
|
-
* @param options.destroyOnReturn When set to `false`, calling `return` on the async iterator,
|
|
414
|
-
* or exiting a `for await...of` iteration using a `break`, `return`, or `throw` will not destroy the stream.
|
|
415
|
-
* **Default: `true`**.
|
|
416
|
-
*/
|
|
417
|
-
iterator(options?: { destroyOnReturn?: boolean }): AsyncIterableIterator<any>;
|
|
418
|
-
/**
|
|
419
|
-
* This method allows mapping over the stream. The *fn* function will be called for every chunk in the stream.
|
|
420
|
-
* If the *fn* function returns a promise - that promise will be `await`ed before being passed to the result stream.
|
|
421
|
-
* @since v17.4.0, v16.14.0
|
|
422
|
-
* @param fn a function to map over every chunk in the stream. Async or not.
|
|
423
|
-
* @returns a stream mapped with the function *fn*.
|
|
424
|
-
*/
|
|
425
|
-
map(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => any, options?: ArrayOptions): Readable;
|
|
426
|
-
/**
|
|
427
|
-
* This method allows filtering the stream. For each chunk in the stream the *fn* function will be called
|
|
428
|
-
* and if it returns a truthy value, the chunk will be passed to the result stream.
|
|
429
|
-
* If the *fn* function returns a promise - that promise will be `await`ed.
|
|
430
|
-
* @since v17.4.0, v16.14.0
|
|
431
|
-
* @param fn a function to filter chunks from the stream. Async or not.
|
|
432
|
-
* @returns a stream filtered with the predicate *fn*.
|
|
433
|
-
*/
|
|
434
|
-
filter(
|
|
435
|
-
fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
|
|
436
|
-
options?: ArrayOptions,
|
|
437
|
-
): Readable;
|
|
438
|
-
/**
|
|
439
|
-
* This method allows iterating a stream. For each chunk in the stream the *fn* function will be called.
|
|
440
|
-
* If the *fn* function returns a promise - that promise will be `await`ed.
|
|
441
|
-
*
|
|
442
|
-
* This method is different from `for await...of` loops in that it can optionally process chunks concurrently.
|
|
443
|
-
* In addition, a `forEach` iteration can only be stopped by having passed a `signal` option
|
|
444
|
-
* and aborting the related AbortController while `for await...of` can be stopped with `break` or `return`.
|
|
445
|
-
* In either case the stream will be destroyed.
|
|
446
|
-
*
|
|
447
|
-
* This method is different from listening to the `'data'` event in that it uses the `readable` event
|
|
448
|
-
* in the underlying machinary and can limit the number of concurrent *fn* calls.
|
|
449
|
-
* @since v17.5.0
|
|
450
|
-
* @param fn a function to call on each chunk of the stream. Async or not.
|
|
451
|
-
* @returns a promise for when the stream has finished.
|
|
452
|
-
*/
|
|
453
|
-
forEach(
|
|
454
|
-
fn: (data: any, options?: Pick<ArrayOptions, "signal">) => void | Promise<void>,
|
|
455
|
-
options?: ArrayOptions,
|
|
456
|
-
): Promise<void>;
|
|
457
|
-
/**
|
|
458
|
-
* This method allows easily obtaining the contents of a stream.
|
|
459
|
-
*
|
|
460
|
-
* As this method reads the entire stream into memory, it negates the benefits of streams. It's intended
|
|
461
|
-
* for interoperability and convenience, not as the primary way to consume streams.
|
|
462
|
-
* @since v17.5.0
|
|
463
|
-
* @returns a promise containing an array with the contents of the stream.
|
|
464
|
-
*/
|
|
465
|
-
toArray(options?: Pick<ArrayOptions, "signal">): Promise<any[]>;
|
|
466
|
-
/**
|
|
467
|
-
* This method is similar to `Array.prototype.some` and calls *fn* on each chunk in the stream
|
|
468
|
-
* until the awaited return value is `true` (or any truthy value). Once an *fn* call on a chunk
|
|
469
|
-
* `await`ed return value is truthy, the stream is destroyed and the promise is fulfilled with `true`.
|
|
470
|
-
* If none of the *fn* calls on the chunks return a truthy value, the promise is fulfilled with `false`.
|
|
471
|
-
* @since v17.5.0
|
|
472
|
-
* @param fn a function to call on each chunk of the stream. Async or not.
|
|
473
|
-
* @returns a promise evaluating to `true` if *fn* returned a truthy value for at least one of the chunks.
|
|
474
|
-
*/
|
|
475
|
-
some(
|
|
476
|
-
fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
|
|
477
|
-
options?: ArrayOptions,
|
|
478
|
-
): Promise<boolean>;
|
|
479
|
-
/**
|
|
480
|
-
* This method is similar to `Array.prototype.find` and calls *fn* on each chunk in the stream
|
|
481
|
-
* to find a chunk with a truthy value for *fn*. Once an *fn* call's awaited return value is truthy,
|
|
482
|
-
* the stream is destroyed and the promise is fulfilled with value for which *fn* returned a truthy value.
|
|
483
|
-
* If all of the *fn* calls on the chunks return a falsy value, the promise is fulfilled with `undefined`.
|
|
484
|
-
* @since v17.5.0
|
|
485
|
-
* @param fn a function to call on each chunk of the stream. Async or not.
|
|
486
|
-
* @returns a promise evaluating to the first chunk for which *fn* evaluated with a truthy value,
|
|
487
|
-
* or `undefined` if no element was found.
|
|
488
|
-
*/
|
|
489
|
-
find<T>(
|
|
490
|
-
fn: (data: any, options?: Pick<ArrayOptions, "signal">) => data is T,
|
|
491
|
-
options?: ArrayOptions,
|
|
492
|
-
): Promise<T | undefined>;
|
|
493
|
-
find(
|
|
494
|
-
fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
|
|
495
|
-
options?: ArrayOptions,
|
|
496
|
-
): Promise<any>;
|
|
497
|
-
/**
|
|
498
|
-
* This method is similar to `Array.prototype.every` and calls *fn* on each chunk in the stream
|
|
499
|
-
* to check if all awaited return values are truthy value for *fn*. Once an *fn* call on a chunk
|
|
500
|
-
* `await`ed return value is falsy, the stream is destroyed and the promise is fulfilled with `false`.
|
|
501
|
-
* If all of the *fn* calls on the chunks return a truthy value, the promise is fulfilled with `true`.
|
|
502
|
-
* @since v17.5.0
|
|
503
|
-
* @param fn a function to call on each chunk of the stream. Async or not.
|
|
504
|
-
* @returns a promise evaluating to `true` if *fn* returned a truthy value for every one of the chunks.
|
|
505
|
-
*/
|
|
506
|
-
every(
|
|
507
|
-
fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
|
|
508
|
-
options?: ArrayOptions,
|
|
509
|
-
): Promise<boolean>;
|
|
510
|
-
/**
|
|
511
|
-
* This method returns a new stream by applying the given callback to each chunk of the stream
|
|
512
|
-
* and then flattening the result.
|
|
513
|
-
*
|
|
514
|
-
* It is possible to return a stream or another iterable or async iterable from *fn* and the result streams
|
|
515
|
-
* will be merged (flattened) into the returned stream.
|
|
516
|
-
* @since v17.5.0
|
|
517
|
-
* @param fn a function to map over every chunk in the stream. May be async. May be a stream or generator.
|
|
518
|
-
* @returns a stream flat-mapped with the function *fn*.
|
|
519
|
-
*/
|
|
520
|
-
flatMap(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => any, options?: ArrayOptions): Readable;
|
|
521
|
-
/**
|
|
522
|
-
* This method returns a new stream with the first *limit* chunks dropped from the start.
|
|
523
|
-
* @since v17.5.0
|
|
524
|
-
* @param limit the number of chunks to drop from the readable.
|
|
525
|
-
* @returns a stream with *limit* chunks dropped from the start.
|
|
526
|
-
*/
|
|
527
|
-
drop(limit: number, options?: Pick<ArrayOptions, "signal">): Readable;
|
|
528
|
-
/**
|
|
529
|
-
* This method returns a new stream with the first *limit* chunks.
|
|
530
|
-
* @since v17.5.0
|
|
531
|
-
* @param limit the number of chunks to take from the readable.
|
|
532
|
-
* @returns a stream with *limit* chunks taken.
|
|
533
|
-
*/
|
|
534
|
-
take(limit: number, options?: Pick<ArrayOptions, "signal">): Readable;
|
|
535
|
-
/**
|
|
536
|
-
* This method returns a new stream with chunks of the underlying stream paired with a counter
|
|
537
|
-
* in the form `[index, chunk]`. The first index value is `0` and it increases by 1 for each chunk produced.
|
|
538
|
-
* @since v17.5.0
|
|
539
|
-
* @returns a stream of indexed pairs.
|
|
540
|
-
*/
|
|
541
|
-
asIndexedPairs(options?: Pick<ArrayOptions, "signal">): Readable;
|
|
542
|
-
/**
|
|
543
|
-
* This method calls *fn* on each chunk of the stream in order, passing it the result from the calculation
|
|
544
|
-
* on the previous element. It returns a promise for the final value of the reduction.
|
|
545
|
-
*
|
|
546
|
-
* If no *initial* value is supplied the first chunk of the stream is used as the initial value.
|
|
547
|
-
* If the stream is empty, the promise is rejected with a `TypeError` with the `ERR_INVALID_ARGS` code property.
|
|
548
|
-
*
|
|
549
|
-
* The reducer function iterates the stream element-by-element which means that there is no *concurrency* parameter
|
|
550
|
-
* or parallelism. To perform a reduce concurrently, you can extract the async function to `readable.map` method.
|
|
551
|
-
* @since v17.5.0
|
|
552
|
-
* @param fn a reducer function to call over every chunk in the stream. Async or not.
|
|
553
|
-
* @param initial the initial value to use in the reduction.
|
|
554
|
-
* @returns a promise for the final value of the reduction.
|
|
555
|
-
*/
|
|
556
|
-
reduce<T = any>(
|
|
557
|
-
fn: (previous: any, data: any, options?: Pick<ArrayOptions, "signal">) => T,
|
|
558
|
-
initial?: undefined,
|
|
559
|
-
options?: Pick<ArrayOptions, "signal">,
|
|
560
|
-
): Promise<T>;
|
|
561
|
-
reduce<T = any>(
|
|
562
|
-
fn: (previous: T, data: any, options?: Pick<ArrayOptions, "signal">) => T,
|
|
563
|
-
initial: T,
|
|
564
|
-
options?: Pick<ArrayOptions, "signal">,
|
|
565
|
-
): Promise<T>;
|
|
566
|
-
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
567
|
-
/**
|
|
568
|
-
* Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'`event (unless `emitClose` is set to `false`). After this call, the readable
|
|
569
|
-
* stream will release any internal resources and subsequent calls to `push()`will be ignored.
|
|
570
|
-
*
|
|
571
|
-
* Once `destroy()` has been called any further calls will be a no-op and no
|
|
572
|
-
* further errors except from `_destroy()` may be emitted as `'error'`.
|
|
573
|
-
*
|
|
574
|
-
* Implementors should not override this method, but instead implement `readable._destroy()`.
|
|
575
|
-
* @since v8.0.0
|
|
576
|
-
* @param error Error which will be passed as payload in `'error'` event
|
|
577
|
-
*/
|
|
578
|
-
destroy(error?: Error): this;
|
|
579
|
-
/**
|
|
580
|
-
* Event emitter
|
|
581
|
-
* The defined events on documents including:
|
|
582
|
-
* 1. close
|
|
583
|
-
* 2. data
|
|
584
|
-
* 3. end
|
|
585
|
-
* 4. error
|
|
586
|
-
* 5. pause
|
|
587
|
-
* 6. readable
|
|
588
|
-
* 7. resume
|
|
589
|
-
*/
|
|
590
|
-
addListener(event: "close", listener: () => void): this;
|
|
591
|
-
addListener(event: "data", listener: (chunk: any) => void): this;
|
|
592
|
-
addListener(event: "end", listener: () => void): this;
|
|
593
|
-
addListener(event: "error", listener: (err: Error) => void): this;
|
|
594
|
-
addListener(event: "pause", listener: () => void): this;
|
|
595
|
-
addListener(event: "readable", listener: () => void): this;
|
|
596
|
-
addListener(event: "resume", listener: () => void): this;
|
|
597
|
-
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
598
|
-
emit(event: "close"): boolean;
|
|
599
|
-
emit(event: "data", chunk: any): boolean;
|
|
600
|
-
emit(event: "end"): boolean;
|
|
601
|
-
emit(event: "error", err: Error): boolean;
|
|
602
|
-
emit(event: "pause"): boolean;
|
|
603
|
-
emit(event: "readable"): boolean;
|
|
604
|
-
emit(event: "resume"): boolean;
|
|
605
|
-
emit(event: string | symbol, ...args: any[]): boolean;
|
|
606
|
-
on(event: "close", listener: () => void): this;
|
|
607
|
-
on(event: "data", listener: (chunk: any) => void): this;
|
|
608
|
-
on(event: "end", listener: () => void): this;
|
|
609
|
-
on(event: "error", listener: (err: Error) => void): this;
|
|
610
|
-
on(event: "pause", listener: () => void): this;
|
|
611
|
-
on(event: "readable", listener: () => void): this;
|
|
612
|
-
on(event: "resume", listener: () => void): this;
|
|
613
|
-
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
614
|
-
once(event: "close", listener: () => void): this;
|
|
615
|
-
once(event: "data", listener: (chunk: any) => void): this;
|
|
616
|
-
once(event: "end", listener: () => void): this;
|
|
617
|
-
once(event: "error", listener: (err: Error) => void): this;
|
|
618
|
-
once(event: "pause", listener: () => void): this;
|
|
619
|
-
once(event: "readable", listener: () => void): this;
|
|
620
|
-
once(event: "resume", listener: () => void): this;
|
|
621
|
-
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
622
|
-
prependListener(event: "close", listener: () => void): this;
|
|
623
|
-
prependListener(event: "data", listener: (chunk: any) => void): this;
|
|
624
|
-
prependListener(event: "end", listener: () => void): this;
|
|
625
|
-
prependListener(event: "error", listener: (err: Error) => void): this;
|
|
626
|
-
prependListener(event: "pause", listener: () => void): this;
|
|
627
|
-
prependListener(event: "readable", listener: () => void): this;
|
|
628
|
-
prependListener(event: "resume", listener: () => void): this;
|
|
629
|
-
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
630
|
-
prependOnceListener(event: "close", listener: () => void): this;
|
|
631
|
-
prependOnceListener(event: "data", listener: (chunk: any) => void): this;
|
|
632
|
-
prependOnceListener(event: "end", listener: () => void): this;
|
|
633
|
-
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
|
634
|
-
prependOnceListener(event: "pause", listener: () => void): this;
|
|
635
|
-
prependOnceListener(event: "readable", listener: () => void): this;
|
|
636
|
-
prependOnceListener(event: "resume", listener: () => void): this;
|
|
637
|
-
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
638
|
-
removeListener(event: "close", listener: () => void): this;
|
|
639
|
-
removeListener(event: "data", listener: (chunk: any) => void): this;
|
|
640
|
-
removeListener(event: "end", listener: () => void): this;
|
|
641
|
-
removeListener(event: "error", listener: (err: Error) => void): this;
|
|
642
|
-
removeListener(event: "pause", listener: () => void): this;
|
|
643
|
-
removeListener(event: "readable", listener: () => void): this;
|
|
644
|
-
removeListener(event: "resume", listener: () => void): this;
|
|
645
|
-
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
646
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
|
|
647
|
-
/**
|
|
648
|
-
* Calls `readable.destroy()` with an `AbortError` and returns a promise that fulfills when the stream is finished.
|
|
649
|
-
* @since v20.4.0
|
|
650
|
-
*/
|
|
651
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
652
|
-
}
|
|
653
|
-
import WritableOptions = internal.WritableOptions;
|
|
654
|
-
class WritableBase extends Stream implements NodeJS.WritableStream {
|
|
655
|
-
/**
|
|
656
|
-
* Is `true` if it is safe to call `writable.write()`, which means
|
|
657
|
-
* the stream has not been destroyed, errored, or ended.
|
|
658
|
-
* @since v11.4.0
|
|
659
|
-
*/
|
|
660
|
-
readonly writable: boolean;
|
|
661
|
-
/**
|
|
662
|
-
* Is `true` after `writable.end()` has been called. This property
|
|
663
|
-
* does not indicate whether the data has been flushed, for this use `writable.writableFinished` instead.
|
|
664
|
-
* @since v12.9.0
|
|
665
|
-
*/
|
|
666
|
-
readonly writableEnded: boolean;
|
|
667
|
-
/**
|
|
668
|
-
* Is set to `true` immediately before the `'finish'` event is emitted.
|
|
669
|
-
* @since v12.6.0
|
|
670
|
-
*/
|
|
671
|
-
readonly writableFinished: boolean;
|
|
672
|
-
/**
|
|
673
|
-
* Return the value of `highWaterMark` passed when creating this `Writable`.
|
|
674
|
-
* @since v9.3.0
|
|
675
|
-
*/
|
|
676
|
-
readonly writableHighWaterMark: number;
|
|
677
|
-
/**
|
|
678
|
-
* This property contains the number of bytes (or objects) in the queue
|
|
679
|
-
* ready to be written. The value provides introspection data regarding
|
|
680
|
-
* the status of the `highWaterMark`.
|
|
681
|
-
* @since v9.4.0
|
|
682
|
-
*/
|
|
683
|
-
readonly writableLength: number;
|
|
684
|
-
/**
|
|
685
|
-
* Getter for the property `objectMode` of a given `Writable` stream.
|
|
686
|
-
* @since v12.3.0
|
|
687
|
-
*/
|
|
688
|
-
readonly writableObjectMode: boolean;
|
|
689
|
-
/**
|
|
690
|
-
* Number of times `writable.uncork()` needs to be
|
|
691
|
-
* called in order to fully uncork the stream.
|
|
692
|
-
* @since v13.2.0, v12.16.0
|
|
693
|
-
*/
|
|
694
|
-
readonly writableCorked: number;
|
|
695
|
-
/**
|
|
696
|
-
* Is `true` after `writable.destroy()` has been called.
|
|
697
|
-
* @since v8.0.0
|
|
698
|
-
*/
|
|
699
|
-
destroyed: boolean;
|
|
700
|
-
/**
|
|
701
|
-
* Is `true` after `'close'` has been emitted.
|
|
702
|
-
* @since v18.0.0
|
|
703
|
-
*/
|
|
704
|
-
readonly closed: boolean;
|
|
705
|
-
/**
|
|
706
|
-
* Returns error if the stream has been destroyed with an error.
|
|
707
|
-
* @since v18.0.0
|
|
708
|
-
*/
|
|
709
|
-
readonly errored: Error | null;
|
|
710
|
-
/**
|
|
711
|
-
* Is `true` if the stream's buffer has been full and stream will emit `'drain'`.
|
|
712
|
-
* @since v15.2.0, v14.17.0
|
|
713
|
-
*/
|
|
714
|
-
readonly writableNeedDrain: boolean;
|
|
715
|
-
constructor(opts?: WritableOptions);
|
|
716
|
-
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
717
|
-
_writev?(
|
|
718
|
-
chunks: Array<{
|
|
719
|
-
chunk: any;
|
|
720
|
-
encoding: BufferEncoding;
|
|
721
|
-
}>,
|
|
722
|
-
callback: (error?: Error | null) => void,
|
|
723
|
-
): void;
|
|
724
|
-
_construct?(callback: (error?: Error | null) => void): void;
|
|
725
|
-
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
726
|
-
_final(callback: (error?: Error | null) => void): void;
|
|
727
|
-
/**
|
|
728
|
-
* The `writable.write()` method writes some data to the stream, and calls the
|
|
729
|
-
* supplied `callback` once the data has been fully handled. If an error
|
|
730
|
-
* occurs, the `callback` will be called with the error as its
|
|
731
|
-
* first argument. The `callback` is called asynchronously and before `'error'` is
|
|
732
|
-
* emitted.
|
|
733
|
-
*
|
|
734
|
-
* The return value is `true` if the internal buffer is less than the`highWaterMark` configured when the stream was created after admitting `chunk`.
|
|
735
|
-
* If `false` is returned, further attempts to write data to the stream should
|
|
736
|
-
* stop until the `'drain'` event is emitted.
|
|
737
|
-
*
|
|
738
|
-
* While a stream is not draining, calls to `write()` will buffer `chunk`, and
|
|
739
|
-
* return false. Once all currently buffered chunks are drained (accepted for
|
|
740
|
-
* delivery by the operating system), the `'drain'` event will be emitted.
|
|
741
|
-
* Once `write()` returns false, do not write more chunks
|
|
742
|
-
* until the `'drain'` event is emitted. While calling `write()` on a stream that
|
|
743
|
-
* is not draining is allowed, Node.js will buffer all written chunks until
|
|
744
|
-
* maximum memory usage occurs, at which point it will abort unconditionally.
|
|
745
|
-
* Even before it aborts, high memory usage will cause poor garbage collector
|
|
746
|
-
* performance and high RSS (which is not typically released back to the system,
|
|
747
|
-
* even after the memory is no longer required). Since TCP sockets may never
|
|
748
|
-
* drain if the remote peer does not read the data, writing a socket that is
|
|
749
|
-
* not draining may lead to a remotely exploitable vulnerability.
|
|
750
|
-
*
|
|
751
|
-
* Writing data while the stream is not draining is particularly
|
|
752
|
-
* problematic for a `Transform`, because the `Transform` streams are paused
|
|
753
|
-
* by default until they are piped or a `'data'` or `'readable'` event handler
|
|
754
|
-
* is added.
|
|
755
|
-
*
|
|
756
|
-
* If the data to be written can be generated or fetched on demand, it is
|
|
757
|
-
* recommended to encapsulate the logic into a `Readable` and use {@link pipe}. However, if calling `write()` is preferred, it is
|
|
758
|
-
* possible to respect backpressure and avoid memory issues using the `'drain'` event:
|
|
759
|
-
*
|
|
760
|
-
* ```js
|
|
761
|
-
* function write(data, cb) {
|
|
762
|
-
* if (!stream.write(data)) {
|
|
763
|
-
* stream.once('drain', cb);
|
|
764
|
-
* } else {
|
|
765
|
-
* process.nextTick(cb);
|
|
766
|
-
* }
|
|
767
|
-
* }
|
|
768
|
-
*
|
|
769
|
-
* // Wait for cb to be called before doing any other write.
|
|
770
|
-
* write('hello', () => {
|
|
771
|
-
* console.log('Write completed, do more writes now.');
|
|
772
|
-
* });
|
|
773
|
-
* ```
|
|
774
|
-
*
|
|
775
|
-
* A `Writable` stream in object mode will always ignore the `encoding` argument.
|
|
776
|
-
* @since v0.9.4
|
|
777
|
-
* @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a string, `Buffer` or `Uint8Array`. For object mode streams, `chunk` may be any
|
|
778
|
-
* JavaScript value other than `null`.
|
|
779
|
-
* @param [encoding='utf8'] The encoding, if `chunk` is a string.
|
|
780
|
-
* @param callback Callback for when this chunk of data is flushed.
|
|
781
|
-
* @return `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.
|
|
782
|
-
*/
|
|
783
|
-
write(chunk: any, callback?: (error: Error | null | undefined) => void): boolean;
|
|
784
|
-
write(chunk: any, encoding: BufferEncoding, callback?: (error: Error | null | undefined) => void): boolean;
|
|
785
|
-
/**
|
|
786
|
-
* The `writable.setDefaultEncoding()` method sets the default `encoding` for a `Writable` stream.
|
|
787
|
-
* @since v0.11.15
|
|
788
|
-
* @param encoding The new default encoding
|
|
789
|
-
*/
|
|
790
|
-
setDefaultEncoding(encoding: BufferEncoding): this;
|
|
791
|
-
/**
|
|
792
|
-
* Calling the `writable.end()` method signals that no more data will be written
|
|
793
|
-
* to the `Writable`. The optional `chunk` and `encoding` arguments allow one
|
|
794
|
-
* final additional chunk of data to be written immediately before closing the
|
|
795
|
-
* stream.
|
|
796
|
-
*
|
|
797
|
-
* Calling the {@link write} method after calling {@link end} will raise an error.
|
|
798
|
-
*
|
|
799
|
-
* ```js
|
|
800
|
-
* // Write 'hello, ' and then end with 'world!'.
|
|
801
|
-
* const fs = require('node:fs');
|
|
802
|
-
* const file = fs.createWriteStream('example.txt');
|
|
803
|
-
* file.write('hello, ');
|
|
804
|
-
* file.end('world!');
|
|
805
|
-
* // Writing more now is not allowed!
|
|
806
|
-
* ```
|
|
807
|
-
* @since v0.9.4
|
|
808
|
-
* @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a string, `Buffer` or `Uint8Array`. For object mode streams, `chunk` may be any
|
|
809
|
-
* JavaScript value other than `null`.
|
|
810
|
-
* @param encoding The encoding if `chunk` is a string
|
|
811
|
-
* @param callback Callback for when the stream is finished.
|
|
812
|
-
*/
|
|
813
|
-
end(cb?: () => void): this;
|
|
814
|
-
end(chunk: any, cb?: () => void): this;
|
|
815
|
-
end(chunk: any, encoding: BufferEncoding, cb?: () => void): this;
|
|
816
|
-
/**
|
|
817
|
-
* The `writable.cork()` method forces all written data to be buffered in memory.
|
|
818
|
-
* The buffered data will be flushed when either the {@link uncork} or {@link end} methods are called.
|
|
819
|
-
*
|
|
820
|
-
* The primary intent of `writable.cork()` is to accommodate a situation in which
|
|
821
|
-
* several small chunks are written to the stream in rapid succession. Instead of
|
|
822
|
-
* immediately forwarding them to the underlying destination, `writable.cork()`buffers all the chunks until `writable.uncork()` is called, which will pass them
|
|
823
|
-
* all to `writable._writev()`, if present. This prevents a head-of-line blocking
|
|
824
|
-
* situation where data is being buffered while waiting for the first small chunk
|
|
825
|
-
* to be processed. However, use of `writable.cork()` without implementing`writable._writev()` may have an adverse effect on throughput.
|
|
826
|
-
*
|
|
827
|
-
* See also: `writable.uncork()`, `writable._writev()`.
|
|
828
|
-
* @since v0.11.2
|
|
829
|
-
*/
|
|
830
|
-
cork(): void;
|
|
831
|
-
/**
|
|
832
|
-
* The `writable.uncork()` method flushes all data buffered since {@link cork} was called.
|
|
833
|
-
*
|
|
834
|
-
* When using `writable.cork()` and `writable.uncork()` to manage the buffering
|
|
835
|
-
* of writes to a stream, defer calls to `writable.uncork()` using`process.nextTick()`. Doing so allows batching of all`writable.write()` calls that occur within a given Node.js event
|
|
836
|
-
* loop phase.
|
|
837
|
-
*
|
|
838
|
-
* ```js
|
|
839
|
-
* stream.cork();
|
|
840
|
-
* stream.write('some ');
|
|
841
|
-
* stream.write('data ');
|
|
842
|
-
* process.nextTick(() => stream.uncork());
|
|
843
|
-
* ```
|
|
844
|
-
*
|
|
845
|
-
* If the `writable.cork()` method is called multiple times on a stream, the
|
|
846
|
-
* same number of calls to `writable.uncork()` must be called to flush the buffered
|
|
847
|
-
* data.
|
|
848
|
-
*
|
|
849
|
-
* ```js
|
|
850
|
-
* stream.cork();
|
|
851
|
-
* stream.write('some ');
|
|
852
|
-
* stream.cork();
|
|
853
|
-
* stream.write('data ');
|
|
854
|
-
* process.nextTick(() => {
|
|
855
|
-
* stream.uncork();
|
|
856
|
-
* // The data will not be flushed until uncork() is called a second time.
|
|
857
|
-
* stream.uncork();
|
|
858
|
-
* });
|
|
859
|
-
* ```
|
|
860
|
-
*
|
|
861
|
-
* See also: `writable.cork()`.
|
|
862
|
-
* @since v0.11.2
|
|
863
|
-
*/
|
|
864
|
-
uncork(): void;
|
|
865
|
-
/**
|
|
866
|
-
* Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'`event (unless `emitClose` is set to `false`). After this call, the writable
|
|
867
|
-
* stream has ended and subsequent calls to `write()` or `end()` will result in
|
|
868
|
-
* an `ERR_STREAM_DESTROYED` error.
|
|
869
|
-
* This is a destructive and immediate way to destroy a stream. Previous calls to`write()` may not have drained, and may trigger an `ERR_STREAM_DESTROYED` error.
|
|
870
|
-
* Use `end()` instead of destroy if data should flush before close, or wait for
|
|
871
|
-
* the `'drain'` event before destroying the stream.
|
|
872
|
-
*
|
|
873
|
-
* Once `destroy()` has been called any further calls will be a no-op and no
|
|
874
|
-
* further errors except from `_destroy()` may be emitted as `'error'`.
|
|
875
|
-
*
|
|
876
|
-
* Implementors should not override this method,
|
|
877
|
-
* but instead implement `writable._destroy()`.
|
|
878
|
-
* @since v8.0.0
|
|
879
|
-
* @param error Optional, an error to emit with `'error'` event.
|
|
880
|
-
*/
|
|
881
|
-
destroy(error?: Error): this;
|
|
882
|
-
/**
|
|
883
|
-
* Event emitter
|
|
884
|
-
* The defined events on documents including:
|
|
885
|
-
* 1. close
|
|
886
|
-
* 2. drain
|
|
887
|
-
* 3. error
|
|
888
|
-
* 4. finish
|
|
889
|
-
* 5. pipe
|
|
890
|
-
* 6. unpipe
|
|
891
|
-
*/
|
|
892
|
-
addListener(event: "close", listener: () => void): this;
|
|
893
|
-
addListener(event: "drain", listener: () => void): this;
|
|
894
|
-
addListener(event: "error", listener: (err: Error) => void): this;
|
|
895
|
-
addListener(event: "finish", listener: () => void): this;
|
|
896
|
-
addListener(event: "pipe", listener: (src: Readable) => void): this;
|
|
897
|
-
addListener(event: "unpipe", listener: (src: Readable) => void): this;
|
|
898
|
-
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
899
|
-
emit(event: "close"): boolean;
|
|
900
|
-
emit(event: "drain"): boolean;
|
|
901
|
-
emit(event: "error", err: Error): boolean;
|
|
902
|
-
emit(event: "finish"): boolean;
|
|
903
|
-
emit(event: "pipe", src: Readable): boolean;
|
|
904
|
-
emit(event: "unpipe", src: Readable): boolean;
|
|
905
|
-
emit(event: string | symbol, ...args: any[]): boolean;
|
|
906
|
-
on(event: "close", listener: () => void): this;
|
|
907
|
-
on(event: "drain", listener: () => void): this;
|
|
908
|
-
on(event: "error", listener: (err: Error) => void): this;
|
|
909
|
-
on(event: "finish", listener: () => void): this;
|
|
910
|
-
on(event: "pipe", listener: (src: Readable) => void): this;
|
|
911
|
-
on(event: "unpipe", listener: (src: Readable) => void): this;
|
|
912
|
-
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
913
|
-
once(event: "close", listener: () => void): this;
|
|
914
|
-
once(event: "drain", listener: () => void): this;
|
|
915
|
-
once(event: "error", listener: (err: Error) => void): this;
|
|
916
|
-
once(event: "finish", listener: () => void): this;
|
|
917
|
-
once(event: "pipe", listener: (src: Readable) => void): this;
|
|
918
|
-
once(event: "unpipe", listener: (src: Readable) => void): this;
|
|
919
|
-
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
920
|
-
prependListener(event: "close", listener: () => void): this;
|
|
921
|
-
prependListener(event: "drain", listener: () => void): this;
|
|
922
|
-
prependListener(event: "error", listener: (err: Error) => void): this;
|
|
923
|
-
prependListener(event: "finish", listener: () => void): this;
|
|
924
|
-
prependListener(event: "pipe", listener: (src: Readable) => void): this;
|
|
925
|
-
prependListener(event: "unpipe", listener: (src: Readable) => void): this;
|
|
926
|
-
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
927
|
-
prependOnceListener(event: "close", listener: () => void): this;
|
|
928
|
-
prependOnceListener(event: "drain", listener: () => void): this;
|
|
929
|
-
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
|
930
|
-
prependOnceListener(event: "finish", listener: () => void): this;
|
|
931
|
-
prependOnceListener(event: "pipe", listener: (src: Readable) => void): this;
|
|
932
|
-
prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this;
|
|
933
|
-
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
934
|
-
removeListener(event: "close", listener: () => void): this;
|
|
935
|
-
removeListener(event: "drain", listener: () => void): this;
|
|
936
|
-
removeListener(event: "error", listener: (err: Error) => void): this;
|
|
937
|
-
removeListener(event: "finish", listener: () => void): this;
|
|
938
|
-
removeListener(event: "pipe", listener: (src: Readable) => void): this;
|
|
939
|
-
removeListener(event: "unpipe", listener: (src: Readable) => void): this;
|
|
940
|
-
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
941
|
-
}
|
|
942
|
-
namespace internal {
|
|
943
|
-
class Stream extends internal {
|
|
944
|
-
constructor(opts?: ReadableOptions);
|
|
945
|
-
}
|
|
43
|
+
namespace Stream {
|
|
946
44
|
interface StreamOptions<T extends Stream> extends Abortable {
|
|
947
45
|
emitClose?: boolean | undefined;
|
|
948
46
|
highWaterMark?: number | undefined;
|
|
949
47
|
objectMode?: boolean | undefined;
|
|
950
|
-
construct
|
|
951
|
-
destroy
|
|
48
|
+
construct?: ((this: T, callback: (error?: Error | null) => void) => void) | undefined;
|
|
49
|
+
destroy?: ((this: T, error: Error | null, callback: (error?: Error | null) => void) => void) | undefined;
|
|
952
50
|
autoDestroy?: boolean | undefined;
|
|
953
51
|
}
|
|
954
|
-
interface ReadableOptions extends StreamOptions<
|
|
955
|
-
encoding?: BufferEncoding | undefined;
|
|
956
|
-
read
|
|
52
|
+
interface ReadableOptions<T extends Readable = Readable> extends StreamOptions<T> {
|
|
53
|
+
encoding?: BufferEncoding | undefined;
|
|
54
|
+
read?: ((this: T, size: number) => void) | undefined;
|
|
55
|
+
}
|
|
56
|
+
interface ArrayOptions {
|
|
57
|
+
/**
|
|
58
|
+
* The maximum concurrent invocations of `fn` to call on the stream at once.
|
|
59
|
+
* @default 1
|
|
60
|
+
*/
|
|
61
|
+
concurrency?: number | undefined;
|
|
62
|
+
/** Allows destroying the stream if the signal is aborted. */
|
|
63
|
+
signal?: AbortSignal | undefined;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @since v0.9.4
|
|
67
|
+
*/
|
|
68
|
+
class Readable extends Stream implements NodeJS.ReadableStream {
|
|
69
|
+
/**
|
|
70
|
+
* A utility method for creating Readable Streams out of iterators.
|
|
71
|
+
* @since v12.3.0, v10.17.0
|
|
72
|
+
* @param iterable Object implementing the `Symbol.asyncIterator` or `Symbol.iterator` iterable protocol. Emits an 'error' event if a null value is passed.
|
|
73
|
+
* @param options Options provided to `new stream.Readable([options])`. By default, `Readable.from()` will set `options.objectMode` to `true`, unless this is explicitly opted out by setting `options.objectMode` to `false`.
|
|
74
|
+
*/
|
|
75
|
+
static from(iterable: Iterable<any> | AsyncIterable<any>, options?: ReadableOptions): Readable;
|
|
76
|
+
/**
|
|
77
|
+
* A utility method for creating a `Readable` from a web `ReadableStream`.
|
|
78
|
+
* @since v17.0.0
|
|
79
|
+
*/
|
|
80
|
+
static fromWeb(
|
|
81
|
+
readableStream: streamWeb.ReadableStream,
|
|
82
|
+
options?: Pick<ReadableOptions, "encoding" | "highWaterMark" | "objectMode" | "signal">,
|
|
83
|
+
): Readable;
|
|
84
|
+
/**
|
|
85
|
+
* A utility method for creating a web `ReadableStream` from a `Readable`.
|
|
86
|
+
* @since v17.0.0
|
|
87
|
+
*/
|
|
88
|
+
static toWeb(
|
|
89
|
+
streamReadable: Readable,
|
|
90
|
+
options?: {
|
|
91
|
+
strategy?: streamWeb.QueuingStrategy | undefined;
|
|
92
|
+
},
|
|
93
|
+
): streamWeb.ReadableStream;
|
|
94
|
+
/**
|
|
95
|
+
* Returns whether the stream has been read from or cancelled.
|
|
96
|
+
* @since v16.8.0
|
|
97
|
+
*/
|
|
98
|
+
static isDisturbed(stream: Readable | NodeJS.ReadableStream): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Returns whether the stream was destroyed or errored before emitting `'end'`.
|
|
101
|
+
* @since v16.8.0
|
|
102
|
+
*/
|
|
103
|
+
readonly readableAborted: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Is `true` if it is safe to call {@link read}, which means
|
|
106
|
+
* the stream has not been destroyed or emitted `'error'` or `'end'`.
|
|
107
|
+
* @since v11.4.0
|
|
108
|
+
*/
|
|
109
|
+
readable: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Returns whether `'data'` has been emitted.
|
|
112
|
+
* @since v16.7.0, v14.18.0
|
|
113
|
+
*/
|
|
114
|
+
readonly readableDidRead: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Getter for the property `encoding` of a given `Readable` stream. The `encoding` property can be set using the {@link setEncoding} method.
|
|
117
|
+
* @since v12.7.0
|
|
118
|
+
*/
|
|
119
|
+
readonly readableEncoding: BufferEncoding | null;
|
|
120
|
+
/**
|
|
121
|
+
* Becomes `true` when [`'end'`](https://nodejs.org/docs/latest-v24.x/api/stream.html#event-end) event is emitted.
|
|
122
|
+
* @since v12.9.0
|
|
123
|
+
*/
|
|
124
|
+
readonly readableEnded: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* This property reflects the current state of a `Readable` stream as described
|
|
127
|
+
* in the [Three states](https://nodejs.org/docs/latest-v24.x/api/stream.html#three-states) section.
|
|
128
|
+
* @since v9.4.0
|
|
129
|
+
*/
|
|
130
|
+
readonly readableFlowing: boolean | null;
|
|
131
|
+
/**
|
|
132
|
+
* Returns the value of `highWaterMark` passed when creating this `Readable`.
|
|
133
|
+
* @since v9.3.0
|
|
134
|
+
*/
|
|
135
|
+
readonly readableHighWaterMark: number;
|
|
136
|
+
/**
|
|
137
|
+
* This property contains the number of bytes (or objects) in the queue
|
|
138
|
+
* ready to be read. The value provides introspection data regarding
|
|
139
|
+
* the status of the `highWaterMark`.
|
|
140
|
+
* @since v9.4.0
|
|
141
|
+
*/
|
|
142
|
+
readonly readableLength: number;
|
|
143
|
+
/**
|
|
144
|
+
* Getter for the property `objectMode` of a given `Readable` stream.
|
|
145
|
+
* @since v12.3.0
|
|
146
|
+
*/
|
|
147
|
+
readonly readableObjectMode: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Is `true` after `readable.destroy()` has been called.
|
|
150
|
+
* @since v8.0.0
|
|
151
|
+
*/
|
|
152
|
+
destroyed: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Is `true` after `'close'` has been emitted.
|
|
155
|
+
* @since v18.0.0
|
|
156
|
+
*/
|
|
157
|
+
readonly closed: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Returns error if the stream has been destroyed with an error.
|
|
160
|
+
* @since v18.0.0
|
|
161
|
+
*/
|
|
162
|
+
readonly errored: Error | null;
|
|
163
|
+
constructor(opts?: ReadableOptions);
|
|
164
|
+
_construct?(callback: (error?: Error | null) => void): void;
|
|
165
|
+
_read(size: number): void;
|
|
166
|
+
/**
|
|
167
|
+
* The `readable.read()` method reads data out of the internal buffer and
|
|
168
|
+
* returns it. If no data is available to be read, `null` is returned. By default,
|
|
169
|
+
* the data is returned as a `Buffer` object unless an encoding has been
|
|
170
|
+
* specified using the `readable.setEncoding()` method or the stream is operating
|
|
171
|
+
* in object mode.
|
|
172
|
+
*
|
|
173
|
+
* The optional `size` argument specifies a specific number of bytes to read. If
|
|
174
|
+
* `size` bytes are not available to be read, `null` will be returned _unless_ the
|
|
175
|
+
* stream has ended, in which case all of the data remaining in the internal buffer
|
|
176
|
+
* will be returned.
|
|
177
|
+
*
|
|
178
|
+
* If the `size` argument is not specified, all of the data contained in the
|
|
179
|
+
* internal buffer will be returned.
|
|
180
|
+
*
|
|
181
|
+
* The `size` argument must be less than or equal to 1 GiB.
|
|
182
|
+
*
|
|
183
|
+
* The `readable.read()` method should only be called on `Readable` streams
|
|
184
|
+
* operating in paused mode. In flowing mode, `readable.read()` is called
|
|
185
|
+
* automatically until the internal buffer is fully drained.
|
|
186
|
+
*
|
|
187
|
+
* ```js
|
|
188
|
+
* const readable = getReadableStreamSomehow();
|
|
189
|
+
*
|
|
190
|
+
* // 'readable' may be triggered multiple times as data is buffered in
|
|
191
|
+
* readable.on('readable', () => {
|
|
192
|
+
* let chunk;
|
|
193
|
+
* console.log('Stream is readable (new data received in buffer)');
|
|
194
|
+
* // Use a loop to make sure we read all currently available data
|
|
195
|
+
* while (null !== (chunk = readable.read())) {
|
|
196
|
+
* console.log(`Read ${chunk.length} bytes of data...`);
|
|
197
|
+
* }
|
|
198
|
+
* });
|
|
199
|
+
*
|
|
200
|
+
* // 'end' will be triggered once when there is no more data available
|
|
201
|
+
* readable.on('end', () => {
|
|
202
|
+
* console.log('Reached end of stream.');
|
|
203
|
+
* });
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* Each call to `readable.read()` returns a chunk of data, or `null`. The chunks
|
|
207
|
+
* are not concatenated. A `while` loop is necessary to consume all data
|
|
208
|
+
* currently in the buffer. When reading a large file `.read()` may return `null`,
|
|
209
|
+
* having consumed all buffered content so far, but there is still more data to
|
|
210
|
+
* come not yet buffered. In this case a new `'readable'` event will be emitted
|
|
211
|
+
* when there is more data in the buffer. Finally the `'end'` event will be
|
|
212
|
+
* emitted when there is no more data to come.
|
|
213
|
+
*
|
|
214
|
+
* Therefore to read a file's whole contents from a `readable`, it is necessary
|
|
215
|
+
* to collect chunks across multiple `'readable'` events:
|
|
216
|
+
*
|
|
217
|
+
* ```js
|
|
218
|
+
* const chunks = [];
|
|
219
|
+
*
|
|
220
|
+
* readable.on('readable', () => {
|
|
221
|
+
* let chunk;
|
|
222
|
+
* while (null !== (chunk = readable.read())) {
|
|
223
|
+
* chunks.push(chunk);
|
|
224
|
+
* }
|
|
225
|
+
* });
|
|
226
|
+
*
|
|
227
|
+
* readable.on('end', () => {
|
|
228
|
+
* const content = chunks.join('');
|
|
229
|
+
* });
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* A `Readable` stream in object mode will always return a single item from
|
|
233
|
+
* a call to `readable.read(size)`, regardless of the value of the `size` argument.
|
|
234
|
+
*
|
|
235
|
+
* If the `readable.read()` method returns a chunk of data, a `'data'` event will
|
|
236
|
+
* also be emitted.
|
|
237
|
+
*
|
|
238
|
+
* Calling {@link read} after the `'end'` event has
|
|
239
|
+
* been emitted will return `null`. No runtime error will be raised.
|
|
240
|
+
* @since v0.9.4
|
|
241
|
+
* @param size Optional argument to specify how much data to read.
|
|
242
|
+
*/
|
|
243
|
+
read(size?: number): any;
|
|
244
|
+
/**
|
|
245
|
+
* The `readable.setEncoding()` method sets the character encoding for
|
|
246
|
+
* data read from the `Readable` stream.
|
|
247
|
+
*
|
|
248
|
+
* By default, no encoding is assigned and stream data will be returned as `Buffer` objects. Setting an encoding causes the stream data
|
|
249
|
+
* to be returned as strings of the specified encoding rather than as `Buffer` objects. For instance, calling `readable.setEncoding('utf8')` will cause the
|
|
250
|
+
* output data to be interpreted as UTF-8 data, and passed as strings. Calling `readable.setEncoding('hex')` will cause the data to be encoded in hexadecimal
|
|
251
|
+
* string format.
|
|
252
|
+
*
|
|
253
|
+
* The `Readable` stream will properly handle multi-byte characters delivered
|
|
254
|
+
* through the stream that would otherwise become improperly decoded if simply
|
|
255
|
+
* pulled from the stream as `Buffer` objects.
|
|
256
|
+
*
|
|
257
|
+
* ```js
|
|
258
|
+
* const readable = getReadableStreamSomehow();
|
|
259
|
+
* readable.setEncoding('utf8');
|
|
260
|
+
* readable.on('data', (chunk) => {
|
|
261
|
+
* assert.equal(typeof chunk, 'string');
|
|
262
|
+
* console.log('Got %d characters of string data:', chunk.length);
|
|
263
|
+
* });
|
|
264
|
+
* ```
|
|
265
|
+
* @since v0.9.4
|
|
266
|
+
* @param encoding The encoding to use.
|
|
267
|
+
*/
|
|
268
|
+
setEncoding(encoding: BufferEncoding): this;
|
|
269
|
+
/**
|
|
270
|
+
* The `readable.pause()` method will cause a stream in flowing mode to stop
|
|
271
|
+
* emitting `'data'` events, switching out of flowing mode. Any data that
|
|
272
|
+
* becomes available will remain in the internal buffer.
|
|
273
|
+
*
|
|
274
|
+
* ```js
|
|
275
|
+
* const readable = getReadableStreamSomehow();
|
|
276
|
+
* readable.on('data', (chunk) => {
|
|
277
|
+
* console.log(`Received ${chunk.length} bytes of data.`);
|
|
278
|
+
* readable.pause();
|
|
279
|
+
* console.log('There will be no additional data for 1 second.');
|
|
280
|
+
* setTimeout(() => {
|
|
281
|
+
* console.log('Now data will start flowing again.');
|
|
282
|
+
* readable.resume();
|
|
283
|
+
* }, 1000);
|
|
284
|
+
* });
|
|
285
|
+
* ```
|
|
286
|
+
*
|
|
287
|
+
* The `readable.pause()` method has no effect if there is a `'readable'` event listener.
|
|
288
|
+
* @since v0.9.4
|
|
289
|
+
*/
|
|
290
|
+
pause(): this;
|
|
291
|
+
/**
|
|
292
|
+
* The `readable.resume()` method causes an explicitly paused `Readable` stream to
|
|
293
|
+
* resume emitting `'data'` events, switching the stream into flowing mode.
|
|
294
|
+
*
|
|
295
|
+
* The `readable.resume()` method can be used to fully consume the data from a
|
|
296
|
+
* stream without actually processing any of that data:
|
|
297
|
+
*
|
|
298
|
+
* ```js
|
|
299
|
+
* getReadableStreamSomehow()
|
|
300
|
+
* .resume()
|
|
301
|
+
* .on('end', () => {
|
|
302
|
+
* console.log('Reached the end, but did not read anything.');
|
|
303
|
+
* });
|
|
304
|
+
* ```
|
|
305
|
+
*
|
|
306
|
+
* The `readable.resume()` method has no effect if there is a `'readable'` event listener.
|
|
307
|
+
* @since v0.9.4
|
|
308
|
+
*/
|
|
309
|
+
resume(): this;
|
|
310
|
+
/**
|
|
311
|
+
* The `readable.isPaused()` method returns the current operating state of the `Readable`.
|
|
312
|
+
* This is used primarily by the mechanism that underlies the `readable.pipe()` method.
|
|
313
|
+
* In most typical cases, there will be no reason to use this method directly.
|
|
314
|
+
*
|
|
315
|
+
* ```js
|
|
316
|
+
* const readable = new stream.Readable();
|
|
317
|
+
*
|
|
318
|
+
* readable.isPaused(); // === false
|
|
319
|
+
* readable.pause();
|
|
320
|
+
* readable.isPaused(); // === true
|
|
321
|
+
* readable.resume();
|
|
322
|
+
* readable.isPaused(); // === false
|
|
323
|
+
* ```
|
|
324
|
+
* @since v0.11.14
|
|
325
|
+
*/
|
|
326
|
+
isPaused(): boolean;
|
|
327
|
+
/**
|
|
328
|
+
* The `readable.unpipe()` method detaches a `Writable` stream previously attached
|
|
329
|
+
* using the {@link pipe} method.
|
|
330
|
+
*
|
|
331
|
+
* If the `destination` is not specified, then _all_ pipes are detached.
|
|
332
|
+
*
|
|
333
|
+
* If the `destination` is specified, but no pipe is set up for it, then
|
|
334
|
+
* the method does nothing.
|
|
335
|
+
*
|
|
336
|
+
* ```js
|
|
337
|
+
* import fs from 'node:fs';
|
|
338
|
+
* const readable = getReadableStreamSomehow();
|
|
339
|
+
* const writable = fs.createWriteStream('file.txt');
|
|
340
|
+
* // All the data from readable goes into 'file.txt',
|
|
341
|
+
* // but only for the first second.
|
|
342
|
+
* readable.pipe(writable);
|
|
343
|
+
* setTimeout(() => {
|
|
344
|
+
* console.log('Stop writing to file.txt.');
|
|
345
|
+
* readable.unpipe(writable);
|
|
346
|
+
* console.log('Manually close the file stream.');
|
|
347
|
+
* writable.end();
|
|
348
|
+
* }, 1000);
|
|
349
|
+
* ```
|
|
350
|
+
* @since v0.9.4
|
|
351
|
+
* @param destination Optional specific stream to unpipe
|
|
352
|
+
*/
|
|
353
|
+
unpipe(destination?: NodeJS.WritableStream): this;
|
|
354
|
+
/**
|
|
355
|
+
* Passing `chunk` as `null` signals the end of the stream (EOF) and behaves the
|
|
356
|
+
* same as `readable.push(null)`, after which no more data can be written. The EOF
|
|
357
|
+
* signal is put at the end of the buffer and any buffered data will still be
|
|
358
|
+
* flushed.
|
|
359
|
+
*
|
|
360
|
+
* The `readable.unshift()` method pushes a chunk of data back into the internal
|
|
361
|
+
* buffer. This is useful in certain situations where a stream is being consumed by
|
|
362
|
+
* code that needs to "un-consume" some amount of data that it has optimistically
|
|
363
|
+
* pulled out of the source, so that the data can be passed on to some other party.
|
|
364
|
+
*
|
|
365
|
+
* The `stream.unshift(chunk)` method cannot be called after the `'end'` event
|
|
366
|
+
* has been emitted or a runtime error will be thrown.
|
|
367
|
+
*
|
|
368
|
+
* Developers using `stream.unshift()` often should consider switching to
|
|
369
|
+
* use of a `Transform` stream instead. See the `API for stream implementers` section for more information.
|
|
370
|
+
*
|
|
371
|
+
* ```js
|
|
372
|
+
* // Pull off a header delimited by \n\n.
|
|
373
|
+
* // Use unshift() if we get too much.
|
|
374
|
+
* // Call the callback with (error, header, stream).
|
|
375
|
+
* import { StringDecoder } from 'node:string_decoder';
|
|
376
|
+
* function parseHeader(stream, callback) {
|
|
377
|
+
* stream.on('error', callback);
|
|
378
|
+
* stream.on('readable', onReadable);
|
|
379
|
+
* const decoder = new StringDecoder('utf8');
|
|
380
|
+
* let header = '';
|
|
381
|
+
* function onReadable() {
|
|
382
|
+
* let chunk;
|
|
383
|
+
* while (null !== (chunk = stream.read())) {
|
|
384
|
+
* const str = decoder.write(chunk);
|
|
385
|
+
* if (str.includes('\n\n')) {
|
|
386
|
+
* // Found the header boundary.
|
|
387
|
+
* const split = str.split(/\n\n/);
|
|
388
|
+
* header += split.shift();
|
|
389
|
+
* const remaining = split.join('\n\n');
|
|
390
|
+
* const buf = Buffer.from(remaining, 'utf8');
|
|
391
|
+
* stream.removeListener('error', callback);
|
|
392
|
+
* // Remove the 'readable' listener before unshifting.
|
|
393
|
+
* stream.removeListener('readable', onReadable);
|
|
394
|
+
* if (buf.length)
|
|
395
|
+
* stream.unshift(buf);
|
|
396
|
+
* // Now the body of the message can be read from the stream.
|
|
397
|
+
* callback(null, header, stream);
|
|
398
|
+
* return;
|
|
399
|
+
* }
|
|
400
|
+
* // Still reading the header.
|
|
401
|
+
* header += str;
|
|
402
|
+
* }
|
|
403
|
+
* }
|
|
404
|
+
* }
|
|
405
|
+
* ```
|
|
406
|
+
*
|
|
407
|
+
* Unlike {@link push}, `stream.unshift(chunk)` will not
|
|
408
|
+
* end the reading process by resetting the internal reading state of the stream.
|
|
409
|
+
* This can cause unexpected results if `readable.unshift()` is called during a
|
|
410
|
+
* read (i.e. from within a {@link _read} implementation on a
|
|
411
|
+
* custom stream). Following the call to `readable.unshift()` with an immediate {@link push} will reset the reading state appropriately,
|
|
412
|
+
* however it is best to simply avoid calling `readable.unshift()` while in the
|
|
413
|
+
* process of performing a read.
|
|
414
|
+
* @since v0.9.11
|
|
415
|
+
* @param chunk Chunk of data to unshift onto the read queue. For streams not operating in object mode, `chunk` must
|
|
416
|
+
* be a {string}, {Buffer}, {TypedArray}, {DataView} or `null`. For object mode streams, `chunk` may be any JavaScript value.
|
|
417
|
+
* @param encoding Encoding of string chunks. Must be a valid `Buffer` encoding, such as `'utf8'` or `'ascii'`.
|
|
418
|
+
*/
|
|
419
|
+
unshift(chunk: any, encoding?: BufferEncoding): void;
|
|
420
|
+
/**
|
|
421
|
+
* 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
|
|
422
|
+
* information.)
|
|
423
|
+
*
|
|
424
|
+
* 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`
|
|
425
|
+
* stream that uses
|
|
426
|
+
* the old stream as its data source.
|
|
427
|
+
*
|
|
428
|
+
* It will rarely be necessary to use `readable.wrap()` but the method has been
|
|
429
|
+
* provided as a convenience for interacting with older Node.js applications and
|
|
430
|
+
* libraries.
|
|
431
|
+
*
|
|
432
|
+
* ```js
|
|
433
|
+
* import { OldReader } from './old-api-module.js';
|
|
434
|
+
* import { Readable } from 'node:stream';
|
|
435
|
+
* const oreader = new OldReader();
|
|
436
|
+
* const myReader = new Readable().wrap(oreader);
|
|
437
|
+
*
|
|
438
|
+
* myReader.on('readable', () => {
|
|
439
|
+
* myReader.read(); // etc.
|
|
440
|
+
* });
|
|
441
|
+
* ```
|
|
442
|
+
* @since v0.9.4
|
|
443
|
+
* @param stream An "old style" readable stream
|
|
444
|
+
*/
|
|
445
|
+
wrap(stream: NodeJS.ReadableStream): this;
|
|
446
|
+
push(chunk: any, encoding?: BufferEncoding): boolean;
|
|
447
|
+
/**
|
|
448
|
+
* The iterator created by this method gives users the option to cancel the destruction
|
|
449
|
+
* of the stream if the `for await...of` loop is exited by `return`, `break`, or `throw`,
|
|
450
|
+
* or if the iterator should destroy the stream if the stream emitted an error during iteration.
|
|
451
|
+
* @since v16.3.0
|
|
452
|
+
* @param options.destroyOnReturn When set to `false`, calling `return` on the async iterator,
|
|
453
|
+
* or exiting a `for await...of` iteration using a `break`, `return`, or `throw` will not destroy the stream.
|
|
454
|
+
* **Default: `true`**.
|
|
455
|
+
*/
|
|
456
|
+
iterator(options?: { destroyOnReturn?: boolean }): NodeJS.AsyncIterator<any>;
|
|
457
|
+
/**
|
|
458
|
+
* This method allows mapping over the stream. The *fn* function will be called for every chunk in the stream.
|
|
459
|
+
* If the *fn* function returns a promise - that promise will be `await`ed before being passed to the result stream.
|
|
460
|
+
* @since v17.4.0, v16.14.0
|
|
461
|
+
* @param fn a function to map over every chunk in the stream. Async or not.
|
|
462
|
+
* @returns a stream mapped with the function *fn*.
|
|
463
|
+
*/
|
|
464
|
+
map(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => any, options?: ArrayOptions): Readable;
|
|
465
|
+
/**
|
|
466
|
+
* This method allows filtering the stream. For each chunk in the stream the *fn* function will be called
|
|
467
|
+
* and if it returns a truthy value, the chunk will be passed to the result stream.
|
|
468
|
+
* If the *fn* function returns a promise - that promise will be `await`ed.
|
|
469
|
+
* @since v17.4.0, v16.14.0
|
|
470
|
+
* @param fn a function to filter chunks from the stream. Async or not.
|
|
471
|
+
* @returns a stream filtered with the predicate *fn*.
|
|
472
|
+
*/
|
|
473
|
+
filter(
|
|
474
|
+
fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
|
|
475
|
+
options?: ArrayOptions,
|
|
476
|
+
): Readable;
|
|
477
|
+
/**
|
|
478
|
+
* This method allows iterating a stream. For each chunk in the stream the *fn* function will be called.
|
|
479
|
+
* If the *fn* function returns a promise - that promise will be `await`ed.
|
|
480
|
+
*
|
|
481
|
+
* This method is different from `for await...of` loops in that it can optionally process chunks concurrently.
|
|
482
|
+
* In addition, a `forEach` iteration can only be stopped by having passed a `signal` option
|
|
483
|
+
* and aborting the related AbortController while `for await...of` can be stopped with `break` or `return`.
|
|
484
|
+
* In either case the stream will be destroyed.
|
|
485
|
+
*
|
|
486
|
+
* This method is different from listening to the `'data'` event in that it uses the `readable` event
|
|
487
|
+
* in the underlying machinary and can limit the number of concurrent *fn* calls.
|
|
488
|
+
* @since v17.5.0
|
|
489
|
+
* @param fn a function to call on each chunk of the stream. Async or not.
|
|
490
|
+
* @returns a promise for when the stream has finished.
|
|
491
|
+
*/
|
|
492
|
+
forEach(
|
|
493
|
+
fn: (data: any, options?: Pick<ArrayOptions, "signal">) => void | Promise<void>,
|
|
494
|
+
options?: ArrayOptions,
|
|
495
|
+
): Promise<void>;
|
|
496
|
+
/**
|
|
497
|
+
* This method allows easily obtaining the contents of a stream.
|
|
498
|
+
*
|
|
499
|
+
* As this method reads the entire stream into memory, it negates the benefits of streams. It's intended
|
|
500
|
+
* for interoperability and convenience, not as the primary way to consume streams.
|
|
501
|
+
* @since v17.5.0
|
|
502
|
+
* @returns a promise containing an array with the contents of the stream.
|
|
503
|
+
*/
|
|
504
|
+
toArray(options?: Pick<ArrayOptions, "signal">): Promise<any[]>;
|
|
505
|
+
/**
|
|
506
|
+
* This method is similar to `Array.prototype.some` and calls *fn* on each chunk in the stream
|
|
507
|
+
* until the awaited return value is `true` (or any truthy value). Once an *fn* call on a chunk
|
|
508
|
+
* `await`ed return value is truthy, the stream is destroyed and the promise is fulfilled with `true`.
|
|
509
|
+
* If none of the *fn* calls on the chunks return a truthy value, the promise is fulfilled with `false`.
|
|
510
|
+
* @since v17.5.0
|
|
511
|
+
* @param fn a function to call on each chunk of the stream. Async or not.
|
|
512
|
+
* @returns a promise evaluating to `true` if *fn* returned a truthy value for at least one of the chunks.
|
|
513
|
+
*/
|
|
514
|
+
some(
|
|
515
|
+
fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
|
|
516
|
+
options?: ArrayOptions,
|
|
517
|
+
): Promise<boolean>;
|
|
518
|
+
/**
|
|
519
|
+
* This method is similar to `Array.prototype.find` and calls *fn* on each chunk in the stream
|
|
520
|
+
* to find a chunk with a truthy value for *fn*. Once an *fn* call's awaited return value is truthy,
|
|
521
|
+
* the stream is destroyed and the promise is fulfilled with value for which *fn* returned a truthy value.
|
|
522
|
+
* If all of the *fn* calls on the chunks return a falsy value, the promise is fulfilled with `undefined`.
|
|
523
|
+
* @since v17.5.0
|
|
524
|
+
* @param fn a function to call on each chunk of the stream. Async or not.
|
|
525
|
+
* @returns a promise evaluating to the first chunk for which *fn* evaluated with a truthy value,
|
|
526
|
+
* or `undefined` if no element was found.
|
|
527
|
+
*/
|
|
528
|
+
find<T>(
|
|
529
|
+
fn: (data: any, options?: Pick<ArrayOptions, "signal">) => data is T,
|
|
530
|
+
options?: ArrayOptions,
|
|
531
|
+
): Promise<T | undefined>;
|
|
532
|
+
find(
|
|
533
|
+
fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
|
|
534
|
+
options?: ArrayOptions,
|
|
535
|
+
): Promise<any>;
|
|
536
|
+
/**
|
|
537
|
+
* This method is similar to `Array.prototype.every` and calls *fn* on each chunk in the stream
|
|
538
|
+
* to check if all awaited return values are truthy value for *fn*. Once an *fn* call on a chunk
|
|
539
|
+
* `await`ed return value is falsy, the stream is destroyed and the promise is fulfilled with `false`.
|
|
540
|
+
* If all of the *fn* calls on the chunks return a truthy value, the promise is fulfilled with `true`.
|
|
541
|
+
* @since v17.5.0
|
|
542
|
+
* @param fn a function to call on each chunk of the stream. Async or not.
|
|
543
|
+
* @returns a promise evaluating to `true` if *fn* returned a truthy value for every one of the chunks.
|
|
544
|
+
*/
|
|
545
|
+
every(
|
|
546
|
+
fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
|
|
547
|
+
options?: ArrayOptions,
|
|
548
|
+
): Promise<boolean>;
|
|
549
|
+
/**
|
|
550
|
+
* This method returns a new stream by applying the given callback to each chunk of the stream
|
|
551
|
+
* and then flattening the result.
|
|
552
|
+
*
|
|
553
|
+
* It is possible to return a stream or another iterable or async iterable from *fn* and the result streams
|
|
554
|
+
* will be merged (flattened) into the returned stream.
|
|
555
|
+
* @since v17.5.0
|
|
556
|
+
* @param fn a function to map over every chunk in the stream. May be async. May be a stream or generator.
|
|
557
|
+
* @returns a stream flat-mapped with the function *fn*.
|
|
558
|
+
*/
|
|
559
|
+
flatMap(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => any, options?: ArrayOptions): Readable;
|
|
560
|
+
/**
|
|
561
|
+
* This method returns a new stream with the first *limit* chunks dropped from the start.
|
|
562
|
+
* @since v17.5.0
|
|
563
|
+
* @param limit the number of chunks to drop from the readable.
|
|
564
|
+
* @returns a stream with *limit* chunks dropped from the start.
|
|
565
|
+
*/
|
|
566
|
+
drop(limit: number, options?: Pick<ArrayOptions, "signal">): Readable;
|
|
567
|
+
/**
|
|
568
|
+
* This method returns a new stream with the first *limit* chunks.
|
|
569
|
+
* @since v17.5.0
|
|
570
|
+
* @param limit the number of chunks to take from the readable.
|
|
571
|
+
* @returns a stream with *limit* chunks taken.
|
|
572
|
+
*/
|
|
573
|
+
take(limit: number, options?: Pick<ArrayOptions, "signal">): Readable;
|
|
574
|
+
/**
|
|
575
|
+
* This method returns a new stream with chunks of the underlying stream paired with a counter
|
|
576
|
+
* in the form `[index, chunk]`. The first index value is `0` and it increases by 1 for each chunk produced.
|
|
577
|
+
* @since v17.5.0
|
|
578
|
+
* @returns a stream of indexed pairs.
|
|
579
|
+
*/
|
|
580
|
+
asIndexedPairs(options?: Pick<ArrayOptions, "signal">): Readable;
|
|
581
|
+
/**
|
|
582
|
+
* This method calls *fn* on each chunk of the stream in order, passing it the result from the calculation
|
|
583
|
+
* on the previous element. It returns a promise for the final value of the reduction.
|
|
584
|
+
*
|
|
585
|
+
* If no *initial* value is supplied the first chunk of the stream is used as the initial value.
|
|
586
|
+
* If the stream is empty, the promise is rejected with a `TypeError` with the `ERR_INVALID_ARGS` code property.
|
|
587
|
+
*
|
|
588
|
+
* The reducer function iterates the stream element-by-element which means that there is no *concurrency* parameter
|
|
589
|
+
* or parallelism. To perform a reduce concurrently, you can extract the async function to `readable.map` method.
|
|
590
|
+
* @since v17.5.0
|
|
591
|
+
* @param fn a reducer function to call over every chunk in the stream. Async or not.
|
|
592
|
+
* @param initial the initial value to use in the reduction.
|
|
593
|
+
* @returns a promise for the final value of the reduction.
|
|
594
|
+
*/
|
|
595
|
+
reduce<T = any>(
|
|
596
|
+
fn: (previous: any, data: any, options?: Pick<ArrayOptions, "signal">) => T,
|
|
597
|
+
initial?: undefined,
|
|
598
|
+
options?: Pick<ArrayOptions, "signal">,
|
|
599
|
+
): Promise<T>;
|
|
600
|
+
reduce<T = any>(
|
|
601
|
+
fn: (previous: T, data: any, options?: Pick<ArrayOptions, "signal">) => T,
|
|
602
|
+
initial: T,
|
|
603
|
+
options?: Pick<ArrayOptions, "signal">,
|
|
604
|
+
): Promise<T>;
|
|
605
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
606
|
+
/**
|
|
607
|
+
* Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'` event (unless `emitClose` is set to `false`). After this call, the readable
|
|
608
|
+
* stream will release any internal resources and subsequent calls to `push()` will be ignored.
|
|
609
|
+
*
|
|
610
|
+
* Once `destroy()` has been called any further calls will be a no-op and no
|
|
611
|
+
* further errors except from `_destroy()` may be emitted as `'error'`.
|
|
612
|
+
*
|
|
613
|
+
* Implementors should not override this method, but instead implement `readable._destroy()`.
|
|
614
|
+
* @since v8.0.0
|
|
615
|
+
* @param error Error which will be passed as payload in `'error'` event
|
|
616
|
+
*/
|
|
617
|
+
destroy(error?: Error): this;
|
|
618
|
+
/**
|
|
619
|
+
* @returns `AsyncIterator` to fully consume the stream.
|
|
620
|
+
* @since v10.0.0
|
|
621
|
+
*/
|
|
622
|
+
[Symbol.asyncIterator](): NodeJS.AsyncIterator<any>;
|
|
623
|
+
/**
|
|
624
|
+
* Calls `readable.destroy()` with an `AbortError` and returns
|
|
625
|
+
* a promise that fulfills when the stream is finished.
|
|
626
|
+
* @since v20.4.0
|
|
627
|
+
*/
|
|
628
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
629
|
+
/**
|
|
630
|
+
* Event emitter
|
|
631
|
+
* The defined events on documents including:
|
|
632
|
+
* 1. close
|
|
633
|
+
* 2. data
|
|
634
|
+
* 3. end
|
|
635
|
+
* 4. error
|
|
636
|
+
* 5. pause
|
|
637
|
+
* 6. readable
|
|
638
|
+
* 7. resume
|
|
639
|
+
*/
|
|
640
|
+
addListener(event: "close", listener: () => void): this;
|
|
641
|
+
addListener(event: "data", listener: (chunk: any) => void): this;
|
|
642
|
+
addListener(event: "end", listener: () => void): this;
|
|
643
|
+
addListener(event: "error", listener: (err: Error) => void): this;
|
|
644
|
+
addListener(event: "pause", listener: () => void): this;
|
|
645
|
+
addListener(event: "readable", listener: () => void): this;
|
|
646
|
+
addListener(event: "resume", listener: () => void): this;
|
|
647
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
648
|
+
emit(event: "close"): boolean;
|
|
649
|
+
emit(event: "data", chunk: any): boolean;
|
|
650
|
+
emit(event: "end"): boolean;
|
|
651
|
+
emit(event: "error", err: Error): boolean;
|
|
652
|
+
emit(event: "pause"): boolean;
|
|
653
|
+
emit(event: "readable"): boolean;
|
|
654
|
+
emit(event: "resume"): boolean;
|
|
655
|
+
emit(event: string | symbol, ...args: any[]): boolean;
|
|
656
|
+
on(event: "close", listener: () => void): this;
|
|
657
|
+
on(event: "data", listener: (chunk: any) => void): this;
|
|
658
|
+
on(event: "end", listener: () => void): this;
|
|
659
|
+
on(event: "error", listener: (err: Error) => void): this;
|
|
660
|
+
on(event: "pause", listener: () => void): this;
|
|
661
|
+
on(event: "readable", listener: () => void): this;
|
|
662
|
+
on(event: "resume", listener: () => void): this;
|
|
663
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
664
|
+
once(event: "close", listener: () => void): this;
|
|
665
|
+
once(event: "data", listener: (chunk: any) => void): this;
|
|
666
|
+
once(event: "end", listener: () => void): this;
|
|
667
|
+
once(event: "error", listener: (err: Error) => void): this;
|
|
668
|
+
once(event: "pause", listener: () => void): this;
|
|
669
|
+
once(event: "readable", listener: () => void): this;
|
|
670
|
+
once(event: "resume", listener: () => void): this;
|
|
671
|
+
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
672
|
+
prependListener(event: "close", listener: () => void): this;
|
|
673
|
+
prependListener(event: "data", listener: (chunk: any) => void): this;
|
|
674
|
+
prependListener(event: "end", listener: () => void): this;
|
|
675
|
+
prependListener(event: "error", listener: (err: Error) => void): this;
|
|
676
|
+
prependListener(event: "pause", listener: () => void): this;
|
|
677
|
+
prependListener(event: "readable", listener: () => void): this;
|
|
678
|
+
prependListener(event: "resume", listener: () => void): this;
|
|
679
|
+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
680
|
+
prependOnceListener(event: "close", listener: () => void): this;
|
|
681
|
+
prependOnceListener(event: "data", listener: (chunk: any) => void): this;
|
|
682
|
+
prependOnceListener(event: "end", listener: () => void): this;
|
|
683
|
+
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
|
684
|
+
prependOnceListener(event: "pause", listener: () => void): this;
|
|
685
|
+
prependOnceListener(event: "readable", listener: () => void): this;
|
|
686
|
+
prependOnceListener(event: "resume", listener: () => void): this;
|
|
687
|
+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
688
|
+
removeListener(event: "close", listener: () => void): this;
|
|
689
|
+
removeListener(event: "data", listener: (chunk: any) => void): this;
|
|
690
|
+
removeListener(event: "end", listener: () => void): this;
|
|
691
|
+
removeListener(event: "error", listener: (err: Error) => void): this;
|
|
692
|
+
removeListener(event: "pause", listener: () => void): this;
|
|
693
|
+
removeListener(event: "readable", listener: () => void): this;
|
|
694
|
+
removeListener(event: "resume", listener: () => void): this;
|
|
695
|
+
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
696
|
+
}
|
|
697
|
+
interface WritableOptions<T extends Writable = Writable> extends StreamOptions<T> {
|
|
698
|
+
decodeStrings?: boolean | undefined;
|
|
699
|
+
defaultEncoding?: BufferEncoding | undefined;
|
|
700
|
+
write?:
|
|
701
|
+
| ((
|
|
702
|
+
this: T,
|
|
703
|
+
chunk: any,
|
|
704
|
+
encoding: BufferEncoding,
|
|
705
|
+
callback: (error?: Error | null) => void,
|
|
706
|
+
) => void)
|
|
707
|
+
| undefined;
|
|
708
|
+
writev?:
|
|
709
|
+
| ((
|
|
710
|
+
this: T,
|
|
711
|
+
chunks: Array<{
|
|
712
|
+
chunk: any;
|
|
713
|
+
encoding: BufferEncoding;
|
|
714
|
+
}>,
|
|
715
|
+
callback: (error?: Error | null) => void,
|
|
716
|
+
) => void)
|
|
717
|
+
| undefined;
|
|
718
|
+
final?: ((this: T, callback: (error?: Error | null) => void) => void) | undefined;
|
|
957
719
|
}
|
|
958
720
|
/**
|
|
959
721
|
* @since v0.9.4
|
|
960
722
|
*/
|
|
961
|
-
class
|
|
723
|
+
class Writable extends Stream implements NodeJS.WritableStream {
|
|
962
724
|
/**
|
|
963
|
-
* A utility method for creating a `
|
|
725
|
+
* A utility method for creating a `Writable` from a web `WritableStream`.
|
|
964
726
|
* @since v17.0.0
|
|
965
|
-
* @experimental
|
|
966
727
|
*/
|
|
967
728
|
static fromWeb(
|
|
968
|
-
|
|
969
|
-
options?: Pick<
|
|
970
|
-
):
|
|
729
|
+
writableStream: streamWeb.WritableStream,
|
|
730
|
+
options?: Pick<WritableOptions, "decodeStrings" | "highWaterMark" | "objectMode" | "signal">,
|
|
731
|
+
): Writable;
|
|
971
732
|
/**
|
|
972
|
-
* A utility method for creating a web `
|
|
733
|
+
* A utility method for creating a web `WritableStream` from a `Writable`.
|
|
973
734
|
* @since v17.0.0
|
|
974
|
-
* @experimental
|
|
975
735
|
*/
|
|
976
|
-
static toWeb(
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
736
|
+
static toWeb(streamWritable: Writable): streamWeb.WritableStream;
|
|
737
|
+
/**
|
|
738
|
+
* Is `true` if it is safe to call `writable.write()`, which means
|
|
739
|
+
* the stream has not been destroyed, errored, or ended.
|
|
740
|
+
* @since v11.4.0
|
|
741
|
+
*/
|
|
742
|
+
readonly writable: boolean;
|
|
743
|
+
/**
|
|
744
|
+
* Returns whether the stream was destroyed or errored before emitting `'finish'`.
|
|
745
|
+
* @since v18.0.0, v16.17.0
|
|
746
|
+
*/
|
|
747
|
+
readonly writableAborted: boolean;
|
|
748
|
+
/**
|
|
749
|
+
* Is `true` after `writable.end()` has been called. This property
|
|
750
|
+
* does not indicate whether the data has been flushed, for this use `writable.writableFinished` instead.
|
|
751
|
+
* @since v12.9.0
|
|
752
|
+
*/
|
|
753
|
+
readonly writableEnded: boolean;
|
|
754
|
+
/**
|
|
755
|
+
* Is set to `true` immediately before the `'finish'` event is emitted.
|
|
756
|
+
* @since v12.6.0
|
|
757
|
+
*/
|
|
758
|
+
readonly writableFinished: boolean;
|
|
759
|
+
/**
|
|
760
|
+
* Return the value of `highWaterMark` passed when creating this `Writable`.
|
|
761
|
+
* @since v9.3.0
|
|
762
|
+
*/
|
|
763
|
+
readonly writableHighWaterMark: number;
|
|
764
|
+
/**
|
|
765
|
+
* This property contains the number of bytes (or objects) in the queue
|
|
766
|
+
* ready to be written. The value provides introspection data regarding
|
|
767
|
+
* the status of the `highWaterMark`.
|
|
768
|
+
* @since v9.4.0
|
|
769
|
+
*/
|
|
770
|
+
readonly writableLength: number;
|
|
771
|
+
/**
|
|
772
|
+
* Getter for the property `objectMode` of a given `Writable` stream.
|
|
773
|
+
* @since v12.3.0
|
|
774
|
+
*/
|
|
775
|
+
readonly writableObjectMode: boolean;
|
|
776
|
+
/**
|
|
777
|
+
* Number of times `writable.uncork()` needs to be
|
|
778
|
+
* called in order to fully uncork the stream.
|
|
779
|
+
* @since v13.2.0, v12.16.0
|
|
780
|
+
*/
|
|
781
|
+
readonly writableCorked: number;
|
|
782
|
+
/**
|
|
783
|
+
* Is `true` after `writable.destroy()` has been called.
|
|
784
|
+
* @since v8.0.0
|
|
785
|
+
*/
|
|
786
|
+
destroyed: boolean;
|
|
787
|
+
/**
|
|
788
|
+
* Is `true` after `'close'` has been emitted.
|
|
789
|
+
* @since v18.0.0
|
|
790
|
+
*/
|
|
791
|
+
readonly closed: boolean;
|
|
792
|
+
/**
|
|
793
|
+
* Returns error if the stream has been destroyed with an error.
|
|
794
|
+
* @since v18.0.0
|
|
795
|
+
*/
|
|
796
|
+
readonly errored: Error | null;
|
|
797
|
+
/**
|
|
798
|
+
* Is `true` if the stream's buffer has been full and stream will emit `'drain'`.
|
|
799
|
+
* @since v15.2.0, v14.17.0
|
|
800
|
+
*/
|
|
801
|
+
readonly writableNeedDrain: boolean;
|
|
802
|
+
constructor(opts?: WritableOptions);
|
|
803
|
+
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
804
|
+
_writev?(
|
|
989
805
|
chunks: Array<{
|
|
990
806
|
chunk: any;
|
|
991
807
|
encoding: BufferEncoding;
|
|
992
808
|
}>,
|
|
993
809
|
callback: (error?: Error | null) => void,
|
|
994
810
|
): void;
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
* @since v0.9.4
|
|
999
|
-
*/
|
|
1000
|
-
class Writable extends WritableBase {
|
|
811
|
+
_construct?(callback: (error?: Error | null) => void): void;
|
|
812
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
813
|
+
_final(callback: (error?: Error | null) => void): void;
|
|
1001
814
|
/**
|
|
1002
|
-
*
|
|
1003
|
-
*
|
|
1004
|
-
*
|
|
815
|
+
* The `writable.write()` method writes some data to the stream, and calls the
|
|
816
|
+
* supplied `callback` once the data has been fully handled. If an error
|
|
817
|
+
* occurs, the `callback` will be called with the error as its
|
|
818
|
+
* first argument. The `callback` is called asynchronously and before `'error'` is
|
|
819
|
+
* emitted.
|
|
820
|
+
*
|
|
821
|
+
* The return value is `true` if the internal buffer is less than the `highWaterMark` configured when the stream was created after admitting `chunk`.
|
|
822
|
+
* If `false` is returned, further attempts to write data to the stream should
|
|
823
|
+
* stop until the `'drain'` event is emitted.
|
|
824
|
+
*
|
|
825
|
+
* While a stream is not draining, calls to `write()` will buffer `chunk`, and
|
|
826
|
+
* return false. Once all currently buffered chunks are drained (accepted for
|
|
827
|
+
* delivery by the operating system), the `'drain'` event will be emitted.
|
|
828
|
+
* Once `write()` returns false, do not write more chunks
|
|
829
|
+
* until the `'drain'` event is emitted. While calling `write()` on a stream that
|
|
830
|
+
* is not draining is allowed, Node.js will buffer all written chunks until
|
|
831
|
+
* maximum memory usage occurs, at which point it will abort unconditionally.
|
|
832
|
+
* Even before it aborts, high memory usage will cause poor garbage collector
|
|
833
|
+
* performance and high RSS (which is not typically released back to the system,
|
|
834
|
+
* even after the memory is no longer required). Since TCP sockets may never
|
|
835
|
+
* drain if the remote peer does not read the data, writing a socket that is
|
|
836
|
+
* not draining may lead to a remotely exploitable vulnerability.
|
|
837
|
+
*
|
|
838
|
+
* Writing data while the stream is not draining is particularly
|
|
839
|
+
* problematic for a `Transform`, because the `Transform` streams are paused
|
|
840
|
+
* by default until they are piped or a `'data'` or `'readable'` event handler
|
|
841
|
+
* is added.
|
|
842
|
+
*
|
|
843
|
+
* If the data to be written can be generated or fetched on demand, it is
|
|
844
|
+
* recommended to encapsulate the logic into a `Readable` and use {@link pipe}. However, if calling `write()` is preferred, it is
|
|
845
|
+
* possible to respect backpressure and avoid memory issues using the `'drain'` event:
|
|
846
|
+
*
|
|
847
|
+
* ```js
|
|
848
|
+
* function write(data, cb) {
|
|
849
|
+
* if (!stream.write(data)) {
|
|
850
|
+
* stream.once('drain', cb);
|
|
851
|
+
* } else {
|
|
852
|
+
* process.nextTick(cb);
|
|
853
|
+
* }
|
|
854
|
+
* }
|
|
855
|
+
*
|
|
856
|
+
* // Wait for cb to be called before doing any other write.
|
|
857
|
+
* write('hello', () => {
|
|
858
|
+
* console.log('Write completed, do more writes now.');
|
|
859
|
+
* });
|
|
860
|
+
* ```
|
|
861
|
+
*
|
|
862
|
+
* A `Writable` stream in object mode will always ignore the `encoding` argument.
|
|
863
|
+
* @since v0.9.4
|
|
864
|
+
* @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a {string}, {Buffer},
|
|
865
|
+
* {TypedArray} or {DataView}. For object mode streams, `chunk` may be any JavaScript value other than `null`.
|
|
866
|
+
* @param callback Callback for when this chunk of data is flushed.
|
|
867
|
+
* @return `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.
|
|
1005
868
|
*/
|
|
1006
|
-
|
|
1007
|
-
writableStream: streamWeb.WritableStream,
|
|
1008
|
-
options?: Pick<WritableOptions, "decodeStrings" | "highWaterMark" | "objectMode" | "signal">,
|
|
1009
|
-
): Writable;
|
|
869
|
+
write(chunk: any, callback?: (error: Error | null | undefined) => void): boolean;
|
|
1010
870
|
/**
|
|
1011
|
-
*
|
|
1012
|
-
* @
|
|
1013
|
-
* @
|
|
871
|
+
* Writes data to the stream, with an explicit encoding for string data.
|
|
872
|
+
* @see {@link Writable.write} for full details.
|
|
873
|
+
* @since v0.9.4
|
|
874
|
+
* @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a {string}, {Buffer},
|
|
875
|
+
* {TypedArray} or {DataView}. For object mode streams, `chunk` may be any JavaScript value other than `null`.
|
|
876
|
+
* @param encoding The encoding, if `chunk` is a string.
|
|
877
|
+
* @param callback Callback for when this chunk of data is flushed.
|
|
878
|
+
* @return `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.
|
|
1014
879
|
*/
|
|
1015
|
-
|
|
880
|
+
write(chunk: any, encoding: BufferEncoding, callback?: (error: Error | null | undefined) => void): boolean;
|
|
881
|
+
/**
|
|
882
|
+
* The `writable.setDefaultEncoding()` method sets the default `encoding` for a `Writable` stream.
|
|
883
|
+
* @since v0.11.15
|
|
884
|
+
* @param encoding The new default encoding
|
|
885
|
+
*/
|
|
886
|
+
setDefaultEncoding(encoding: BufferEncoding): this;
|
|
887
|
+
/**
|
|
888
|
+
* Calling the `writable.end()` method signals that no more data will be written
|
|
889
|
+
* to the `Writable`. The optional `chunk` and `encoding` arguments allow one
|
|
890
|
+
* final additional chunk of data to be written immediately before closing the
|
|
891
|
+
* stream.
|
|
892
|
+
*
|
|
893
|
+
* Calling the {@link write} method after calling {@link end} will raise an error.
|
|
894
|
+
*
|
|
895
|
+
* ```js
|
|
896
|
+
* // Write 'hello, ' and then end with 'world!'.
|
|
897
|
+
* import fs from 'node:fs';
|
|
898
|
+
* const file = fs.createWriteStream('example.txt');
|
|
899
|
+
* file.write('hello, ');
|
|
900
|
+
* file.end('world!');
|
|
901
|
+
* // Writing more now is not allowed!
|
|
902
|
+
* ```
|
|
903
|
+
* @since v0.9.4
|
|
904
|
+
* @param cb Callback for when the stream is finished.
|
|
905
|
+
*/
|
|
906
|
+
end(cb?: () => void): this;
|
|
907
|
+
/**
|
|
908
|
+
* Signals that no more data will be written, with one final chunk of data.
|
|
909
|
+
* @see {@link Writable.end} for full details.
|
|
910
|
+
* @since v0.9.4
|
|
911
|
+
* @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a {string}, {Buffer},
|
|
912
|
+
* {TypedArray} or {DataView}. For object mode streams, `chunk` may be any JavaScript value other than `null`.
|
|
913
|
+
* @param cb Callback for when the stream is finished.
|
|
914
|
+
*/
|
|
915
|
+
end(chunk: any, cb?: () => void): this;
|
|
916
|
+
/**
|
|
917
|
+
* Signals that no more data will be written, with one final chunk of data.
|
|
918
|
+
* @see {@link Writable.end} for full details.
|
|
919
|
+
* @since v0.9.4
|
|
920
|
+
* @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a {string}, {Buffer},
|
|
921
|
+
* {TypedArray} or {DataView}. For object mode streams, `chunk` may be any JavaScript value other than `null`.
|
|
922
|
+
* @param encoding The encoding if `chunk` is a string
|
|
923
|
+
* @param cb Callback for when the stream is finished.
|
|
924
|
+
*/
|
|
925
|
+
end(chunk: any, encoding: BufferEncoding, cb?: () => void): this;
|
|
926
|
+
/**
|
|
927
|
+
* The `writable.cork()` method forces all written data to be buffered in memory.
|
|
928
|
+
* The buffered data will be flushed when either the {@link uncork} or {@link end} methods are called.
|
|
929
|
+
*
|
|
930
|
+
* The primary intent of `writable.cork()` is to accommodate a situation in which
|
|
931
|
+
* several small chunks are written to the stream in rapid succession. Instead of
|
|
932
|
+
* immediately forwarding them to the underlying destination, `writable.cork()` buffers all the chunks until `writable.uncork()` is called, which will pass them
|
|
933
|
+
* all to `writable._writev()`, if present. This prevents a head-of-line blocking
|
|
934
|
+
* situation where data is being buffered while waiting for the first small chunk
|
|
935
|
+
* to be processed. However, use of `writable.cork()` without implementing `writable._writev()` may have an adverse effect on throughput.
|
|
936
|
+
*
|
|
937
|
+
* See also: `writable.uncork()`, `writable._writev()`.
|
|
938
|
+
* @since v0.11.2
|
|
939
|
+
*/
|
|
940
|
+
cork(): void;
|
|
941
|
+
/**
|
|
942
|
+
* The `writable.uncork()` method flushes all data buffered since {@link cork} was called.
|
|
943
|
+
*
|
|
944
|
+
* When using `writable.cork()` and `writable.uncork()` to manage the buffering
|
|
945
|
+
* of writes to a stream, defer calls to `writable.uncork()` using `process.nextTick()`. Doing so allows batching of all `writable.write()` calls that occur within a given Node.js event
|
|
946
|
+
* loop phase.
|
|
947
|
+
*
|
|
948
|
+
* ```js
|
|
949
|
+
* stream.cork();
|
|
950
|
+
* stream.write('some ');
|
|
951
|
+
* stream.write('data ');
|
|
952
|
+
* process.nextTick(() => stream.uncork());
|
|
953
|
+
* ```
|
|
954
|
+
*
|
|
955
|
+
* If the `writable.cork()` method is called multiple times on a stream, the
|
|
956
|
+
* same number of calls to `writable.uncork()` must be called to flush the buffered
|
|
957
|
+
* data.
|
|
958
|
+
*
|
|
959
|
+
* ```js
|
|
960
|
+
* stream.cork();
|
|
961
|
+
* stream.write('some ');
|
|
962
|
+
* stream.cork();
|
|
963
|
+
* stream.write('data ');
|
|
964
|
+
* process.nextTick(() => {
|
|
965
|
+
* stream.uncork();
|
|
966
|
+
* // The data will not be flushed until uncork() is called a second time.
|
|
967
|
+
* stream.uncork();
|
|
968
|
+
* });
|
|
969
|
+
* ```
|
|
970
|
+
*
|
|
971
|
+
* See also: `writable.cork()`.
|
|
972
|
+
* @since v0.11.2
|
|
973
|
+
*/
|
|
974
|
+
uncork(): void;
|
|
975
|
+
/**
|
|
976
|
+
* Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'` event (unless `emitClose` is set to `false`). After this call, the writable
|
|
977
|
+
* stream has ended and subsequent calls to `write()` or `end()` will result in
|
|
978
|
+
* an `ERR_STREAM_DESTROYED` error.
|
|
979
|
+
* This is a destructive and immediate way to destroy a stream. Previous calls to `write()` may not have drained, and may trigger an `ERR_STREAM_DESTROYED` error.
|
|
980
|
+
* Use `end()` instead of destroy if data should flush before close, or wait for
|
|
981
|
+
* the `'drain'` event before destroying the stream.
|
|
982
|
+
*
|
|
983
|
+
* Once `destroy()` has been called any further calls will be a no-op and no
|
|
984
|
+
* further errors except from `_destroy()` may be emitted as `'error'`.
|
|
985
|
+
*
|
|
986
|
+
* Implementors should not override this method,
|
|
987
|
+
* but instead implement `writable._destroy()`.
|
|
988
|
+
* @since v8.0.0
|
|
989
|
+
* @param error Optional, an error to emit with `'error'` event.
|
|
990
|
+
*/
|
|
991
|
+
destroy(error?: Error): this;
|
|
992
|
+
/**
|
|
993
|
+
* Calls `writable.destroy()` with an `AbortError` and returns
|
|
994
|
+
* a promise that fulfills when the stream is finished.
|
|
995
|
+
* @since v22.4.0, v20.16.0
|
|
996
|
+
*/
|
|
997
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
998
|
+
/**
|
|
999
|
+
* Event emitter
|
|
1000
|
+
* The defined events on documents including:
|
|
1001
|
+
* 1. close
|
|
1002
|
+
* 2. drain
|
|
1003
|
+
* 3. error
|
|
1004
|
+
* 4. finish
|
|
1005
|
+
* 5. pipe
|
|
1006
|
+
* 6. unpipe
|
|
1007
|
+
*/
|
|
1008
|
+
addListener(event: "close", listener: () => void): this;
|
|
1009
|
+
addListener(event: "drain", listener: () => void): this;
|
|
1010
|
+
addListener(event: "error", listener: (err: Error) => void): this;
|
|
1011
|
+
addListener(event: "finish", listener: () => void): this;
|
|
1012
|
+
addListener(event: "pipe", listener: (src: Readable) => void): this;
|
|
1013
|
+
addListener(event: "unpipe", listener: (src: Readable) => void): this;
|
|
1014
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
1015
|
+
emit(event: "close"): boolean;
|
|
1016
|
+
emit(event: "drain"): boolean;
|
|
1017
|
+
emit(event: "error", err: Error): boolean;
|
|
1018
|
+
emit(event: "finish"): boolean;
|
|
1019
|
+
emit(event: "pipe", src: Readable): boolean;
|
|
1020
|
+
emit(event: "unpipe", src: Readable): boolean;
|
|
1021
|
+
emit(event: string | symbol, ...args: any[]): boolean;
|
|
1022
|
+
on(event: "close", listener: () => void): this;
|
|
1023
|
+
on(event: "drain", listener: () => void): this;
|
|
1024
|
+
on(event: "error", listener: (err: Error) => void): this;
|
|
1025
|
+
on(event: "finish", listener: () => void): this;
|
|
1026
|
+
on(event: "pipe", listener: (src: Readable) => void): this;
|
|
1027
|
+
on(event: "unpipe", listener: (src: Readable) => void): this;
|
|
1028
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
1029
|
+
once(event: "close", listener: () => void): this;
|
|
1030
|
+
once(event: "drain", listener: () => void): this;
|
|
1031
|
+
once(event: "error", listener: (err: Error) => void): this;
|
|
1032
|
+
once(event: "finish", listener: () => void): this;
|
|
1033
|
+
once(event: "pipe", listener: (src: Readable) => void): this;
|
|
1034
|
+
once(event: "unpipe", listener: (src: Readable) => void): this;
|
|
1035
|
+
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
1036
|
+
prependListener(event: "close", listener: () => void): this;
|
|
1037
|
+
prependListener(event: "drain", listener: () => void): this;
|
|
1038
|
+
prependListener(event: "error", listener: (err: Error) => void): this;
|
|
1039
|
+
prependListener(event: "finish", listener: () => void): this;
|
|
1040
|
+
prependListener(event: "pipe", listener: (src: Readable) => void): this;
|
|
1041
|
+
prependListener(event: "unpipe", listener: (src: Readable) => void): this;
|
|
1042
|
+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
1043
|
+
prependOnceListener(event: "close", listener: () => void): this;
|
|
1044
|
+
prependOnceListener(event: "drain", listener: () => void): this;
|
|
1045
|
+
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
|
1046
|
+
prependOnceListener(event: "finish", listener: () => void): this;
|
|
1047
|
+
prependOnceListener(event: "pipe", listener: (src: Readable) => void): this;
|
|
1048
|
+
prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this;
|
|
1049
|
+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
1050
|
+
removeListener(event: "close", listener: () => void): this;
|
|
1051
|
+
removeListener(event: "drain", listener: () => void): this;
|
|
1052
|
+
removeListener(event: "error", listener: (err: Error) => void): this;
|
|
1053
|
+
removeListener(event: "finish", listener: () => void): this;
|
|
1054
|
+
removeListener(event: "pipe", listener: (src: Readable) => void): this;
|
|
1055
|
+
removeListener(event: "unpipe", listener: (src: Readable) => void): this;
|
|
1056
|
+
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
1016
1057
|
}
|
|
1017
|
-
interface DuplexOptions extends ReadableOptions
|
|
1058
|
+
interface DuplexOptions<T extends Duplex = Duplex> extends ReadableOptions<T>, WritableOptions<T> {
|
|
1018
1059
|
allowHalfOpen?: boolean | undefined;
|
|
1019
1060
|
readableObjectMode?: boolean | undefined;
|
|
1020
1061
|
writableObjectMode?: boolean | undefined;
|
|
1021
1062
|
readableHighWaterMark?: number | undefined;
|
|
1022
1063
|
writableHighWaterMark?: number | undefined;
|
|
1023
1064
|
writableCorked?: number | undefined;
|
|
1024
|
-
construct?(this: Duplex, callback: (error?: Error | null) => void): void;
|
|
1025
|
-
read?(this: Duplex, size: number): void;
|
|
1026
|
-
write?(this: Duplex, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
1027
|
-
writev?(
|
|
1028
|
-
this: Duplex,
|
|
1029
|
-
chunks: Array<{
|
|
1030
|
-
chunk: any;
|
|
1031
|
-
encoding: BufferEncoding;
|
|
1032
|
-
}>,
|
|
1033
|
-
callback: (error?: Error | null) => void,
|
|
1034
|
-
): void;
|
|
1035
|
-
final?(this: Duplex, callback: (error?: Error | null) => void): void;
|
|
1036
|
-
destroy?(this: Duplex, error: Error | null, callback: (error: Error | null) => void): void;
|
|
1037
1065
|
}
|
|
1038
1066
|
/**
|
|
1039
1067
|
* Duplex streams are streams that implement both the `Readable` and `Writable` interfaces.
|
|
@@ -1045,24 +1073,14 @@ declare module "stream" {
|
|
|
1045
1073
|
* * `crypto streams`
|
|
1046
1074
|
* @since v0.9.4
|
|
1047
1075
|
*/
|
|
1048
|
-
class Duplex extends
|
|
1049
|
-
readonly writable: boolean;
|
|
1050
|
-
readonly writableEnded: boolean;
|
|
1051
|
-
readonly writableFinished: boolean;
|
|
1052
|
-
readonly writableHighWaterMark: number;
|
|
1053
|
-
readonly writableLength: number;
|
|
1054
|
-
readonly writableObjectMode: boolean;
|
|
1055
|
-
readonly writableCorked: number;
|
|
1056
|
-
readonly writableNeedDrain: boolean;
|
|
1057
|
-
readonly closed: boolean;
|
|
1058
|
-
readonly errored: Error | null;
|
|
1076
|
+
class Duplex extends Stream implements NodeJS.ReadWriteStream {
|
|
1059
1077
|
/**
|
|
1060
1078
|
* If `false` then the stream will automatically end the writable side when the
|
|
1061
1079
|
* readable side ends. Set initially by the `allowHalfOpen` constructor option,
|
|
1062
1080
|
* which defaults to `true`.
|
|
1063
1081
|
*
|
|
1064
|
-
* This can be changed manually to change the half-open behavior of an existing
|
|
1065
|
-
* emitted.
|
|
1082
|
+
* This can be changed manually to change the half-open behavior of an existing
|
|
1083
|
+
* `Duplex` stream instance, but must be changed before the `'end'` event is emitted.
|
|
1066
1084
|
* @since v0.9.4
|
|
1067
1085
|
*/
|
|
1068
1086
|
allowHalfOpen: boolean;
|
|
@@ -1100,28 +1118,9 @@ declare module "stream" {
|
|
|
1100
1118
|
| Promise<any>
|
|
1101
1119
|
| Object,
|
|
1102
1120
|
): Duplex;
|
|
1103
|
-
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
1104
|
-
_writev?(
|
|
1105
|
-
chunks: Array<{
|
|
1106
|
-
chunk: any;
|
|
1107
|
-
encoding: BufferEncoding;
|
|
1108
|
-
}>,
|
|
1109
|
-
callback: (error?: Error | null) => void,
|
|
1110
|
-
): void;
|
|
1111
|
-
_destroy(error: Error | null, callback: (error: Error | null) => void): void;
|
|
1112
|
-
_final(callback: (error?: Error | null) => void): void;
|
|
1113
|
-
write(chunk: any, encoding?: BufferEncoding, cb?: (error: Error | null | undefined) => void): boolean;
|
|
1114
|
-
write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
|
|
1115
|
-
setDefaultEncoding(encoding: BufferEncoding): this;
|
|
1116
|
-
end(cb?: () => void): this;
|
|
1117
|
-
end(chunk: any, cb?: () => void): this;
|
|
1118
|
-
end(chunk: any, encoding?: BufferEncoding, cb?: () => void): this;
|
|
1119
|
-
cork(): void;
|
|
1120
|
-
uncork(): void;
|
|
1121
1121
|
/**
|
|
1122
1122
|
* A utility method for creating a web `ReadableStream` and `WritableStream` from a `Duplex`.
|
|
1123
1123
|
* @since v17.0.0
|
|
1124
|
-
* @experimental
|
|
1125
1124
|
*/
|
|
1126
1125
|
static toWeb(streamDuplex: Duplex): {
|
|
1127
1126
|
readable: streamWeb.ReadableStream;
|
|
@@ -1130,7 +1129,6 @@ declare module "stream" {
|
|
|
1130
1129
|
/**
|
|
1131
1130
|
* A utility method for creating a `Duplex` from a web `ReadableStream` and `WritableStream`.
|
|
1132
1131
|
* @since v17.0.0
|
|
1133
|
-
* @experimental
|
|
1134
1132
|
*/
|
|
1135
1133
|
static fromWeb(
|
|
1136
1134
|
duplexStream: {
|
|
@@ -1242,28 +1240,32 @@ declare module "stream" {
|
|
|
1242
1240
|
removeListener(event: "unpipe", listener: (src: Readable) => void): this;
|
|
1243
1241
|
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
1244
1242
|
}
|
|
1243
|
+
interface Duplex extends Readable, Writable {}
|
|
1244
|
+
/**
|
|
1245
|
+
* The utility function `duplexPair` returns an Array with two items,
|
|
1246
|
+
* each being a `Duplex` stream connected to the other side:
|
|
1247
|
+
*
|
|
1248
|
+
* ```js
|
|
1249
|
+
* const [ sideA, sideB ] = duplexPair();
|
|
1250
|
+
* ```
|
|
1251
|
+
*
|
|
1252
|
+
* Whatever is written to one stream is made readable on the other. It provides
|
|
1253
|
+
* behavior analogous to a network connection, where the data written by the client
|
|
1254
|
+
* becomes readable by the server, and vice-versa.
|
|
1255
|
+
*
|
|
1256
|
+
* The Duplex streams are symmetrical; one or the other may be used without any
|
|
1257
|
+
* difference in behavior.
|
|
1258
|
+
* @param options A value to pass to both {@link Duplex} constructors,
|
|
1259
|
+
* to set options such as buffering.
|
|
1260
|
+
* @since v22.6.0
|
|
1261
|
+
*/
|
|
1262
|
+
function duplexPair(options?: DuplexOptions): [Duplex, Duplex];
|
|
1245
1263
|
type TransformCallback = (error?: Error | null, data?: any) => void;
|
|
1246
|
-
interface TransformOptions extends DuplexOptions {
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
chunk: any,
|
|
1252
|
-
encoding: BufferEncoding,
|
|
1253
|
-
callback: (error?: Error | null) => void,
|
|
1254
|
-
): void;
|
|
1255
|
-
writev?(
|
|
1256
|
-
this: Transform,
|
|
1257
|
-
chunks: Array<{
|
|
1258
|
-
chunk: any;
|
|
1259
|
-
encoding: BufferEncoding;
|
|
1260
|
-
}>,
|
|
1261
|
-
callback: (error?: Error | null) => void,
|
|
1262
|
-
): void;
|
|
1263
|
-
final?(this: Transform, callback: (error?: Error | null) => void): void;
|
|
1264
|
-
destroy?(this: Transform, error: Error | null, callback: (error: Error | null) => void): void;
|
|
1265
|
-
transform?(this: Transform, chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
|
|
1266
|
-
flush?(this: Transform, callback: TransformCallback): void;
|
|
1264
|
+
interface TransformOptions<T extends Transform = Transform> extends DuplexOptions<T> {
|
|
1265
|
+
transform?:
|
|
1266
|
+
| ((this: T, chunk: any, encoding: BufferEncoding, callback: TransformCallback) => void)
|
|
1267
|
+
| undefined;
|
|
1268
|
+
flush?: ((this: T, callback: TransformCallback) => void) | undefined;
|
|
1267
1269
|
}
|
|
1268
1270
|
/**
|
|
1269
1271
|
* Transform streams are `Duplex` streams where the output is in some way
|
|
@@ -1283,7 +1285,7 @@ declare module "stream" {
|
|
|
1283
1285
|
}
|
|
1284
1286
|
/**
|
|
1285
1287
|
* The `stream.PassThrough` class is a trivial implementation of a `Transform` stream that simply passes the input bytes across to the output. Its purpose is
|
|
1286
|
-
* primarily for examples and testing, but there are some use cases where`stream.PassThrough` is useful as a building block for novel sorts of streams.
|
|
1288
|
+
* primarily for examples and testing, but there are some use cases where `stream.PassThrough` is useful as a building block for novel sorts of streams.
|
|
1287
1289
|
*/
|
|
1288
1290
|
class PassThrough extends Transform {}
|
|
1289
1291
|
/**
|
|
@@ -1292,11 +1294,11 @@ declare module "stream" {
|
|
|
1292
1294
|
* Attaches an AbortSignal to a readable or writeable stream. This lets code
|
|
1293
1295
|
* control stream destruction using an `AbortController`.
|
|
1294
1296
|
*
|
|
1295
|
-
* Calling `abort` on the `AbortController` corresponding to the passed`AbortSignal` will behave the same way as calling `.destroy(new AbortError())`on the
|
|
1296
|
-
* AbortError())` for webstreams.
|
|
1297
|
+
* Calling `abort` on the `AbortController` corresponding to the passed `AbortSignal` will behave the same way as calling `.destroy(new AbortError())` on the
|
|
1298
|
+
* stream, and `controller.error(new AbortError())` for webstreams.
|
|
1297
1299
|
*
|
|
1298
1300
|
* ```js
|
|
1299
|
-
*
|
|
1301
|
+
* import fs from 'node:fs';
|
|
1300
1302
|
*
|
|
1301
1303
|
* const controller = new AbortController();
|
|
1302
1304
|
* const read = addAbortSignal(
|
|
@@ -1363,20 +1365,18 @@ declare module "stream" {
|
|
|
1363
1365
|
* ```
|
|
1364
1366
|
* @since v15.4.0
|
|
1365
1367
|
* @param signal A signal representing possible cancellation
|
|
1366
|
-
* @param stream
|
|
1368
|
+
* @param stream A stream to attach a signal to.
|
|
1367
1369
|
*/
|
|
1368
1370
|
function addAbortSignal<T extends Stream>(signal: AbortSignal, stream: T): T;
|
|
1369
1371
|
/**
|
|
1370
1372
|
* Returns the default highWaterMark used by streams.
|
|
1371
|
-
* Defaults to `
|
|
1373
|
+
* Defaults to `65536` (64 KiB), or `16` for `objectMode`.
|
|
1372
1374
|
* @since v19.9.0
|
|
1373
|
-
* @param objectMode
|
|
1374
1375
|
*/
|
|
1375
1376
|
function getDefaultHighWaterMark(objectMode: boolean): number;
|
|
1376
1377
|
/**
|
|
1377
1378
|
* Sets the default highWaterMark used by streams.
|
|
1378
1379
|
* @since v19.9.0
|
|
1379
|
-
* @param objectMode
|
|
1380
1380
|
* @param value highWaterMark value
|
|
1381
1381
|
*/
|
|
1382
1382
|
function setDefaultHighWaterMark(objectMode: boolean, value: number): void;
|
|
@@ -1392,8 +1392,8 @@ declare module "stream" {
|
|
|
1392
1392
|
* or has experienced an error or a premature close event.
|
|
1393
1393
|
*
|
|
1394
1394
|
* ```js
|
|
1395
|
-
*
|
|
1396
|
-
*
|
|
1395
|
+
* import { finished } from 'node:stream';
|
|
1396
|
+
* import fs from 'node:fs';
|
|
1397
1397
|
*
|
|
1398
1398
|
* const rs = fs.createReadStream('archive.tar');
|
|
1399
1399
|
*
|
|
@@ -1409,11 +1409,11 @@ declare module "stream" {
|
|
|
1409
1409
|
* ```
|
|
1410
1410
|
*
|
|
1411
1411
|
* Especially useful in error handling scenarios where a stream is destroyed
|
|
1412
|
-
* prematurely (like an aborted HTTP request), and will not emit `'end'`or `'finish'`.
|
|
1412
|
+
* prematurely (like an aborted HTTP request), and will not emit `'end'` or `'finish'`.
|
|
1413
1413
|
*
|
|
1414
|
-
* The `finished` API provides `promise version
|
|
1414
|
+
* The `finished` API provides [`promise version`](https://nodejs.org/docs/latest-v24.x/api/stream.html#streamfinishedstream-options).
|
|
1415
1415
|
*
|
|
1416
|
-
* `stream.finished()` leaves dangling event listeners (in particular`'error'`, `'end'`, `'finish'` and `'close'`) after `callback` has been
|
|
1416
|
+
* `stream.finished()` leaves dangling event listeners (in particular `'error'`, `'end'`, `'finish'` and `'close'`) after `callback` has been
|
|
1417
1417
|
* invoked. The reason for this is so that unexpected `'error'` events (due to
|
|
1418
1418
|
* incorrect stream implementations) do not cause unexpected crashes.
|
|
1419
1419
|
* If this is unwanted behavior then the returned cleanup function needs to be
|
|
@@ -1428,7 +1428,7 @@ declare module "stream" {
|
|
|
1428
1428
|
* @since v10.0.0
|
|
1429
1429
|
* @param stream A readable and/or writable stream.
|
|
1430
1430
|
* @param callback A callback function that takes an optional error argument.
|
|
1431
|
-
* @
|
|
1431
|
+
* @returns A cleanup function which removes all registered listeners.
|
|
1432
1432
|
*/
|
|
1433
1433
|
function finished(
|
|
1434
1434
|
stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream,
|
|
@@ -1476,9 +1476,9 @@ declare module "stream" {
|
|
|
1476
1476
|
* properly cleaning up and provide a callback when the pipeline is complete.
|
|
1477
1477
|
*
|
|
1478
1478
|
* ```js
|
|
1479
|
-
*
|
|
1480
|
-
*
|
|
1481
|
-
*
|
|
1479
|
+
* import { pipeline } from 'node:stream';
|
|
1480
|
+
* import fs from 'node:fs';
|
|
1481
|
+
* import zlib from 'node:zlib';
|
|
1482
1482
|
*
|
|
1483
1483
|
* // Use the pipeline API to easily pipe a series of streams
|
|
1484
1484
|
* // together and get notified when the pipeline is fully done.
|
|
@@ -1499,7 +1499,7 @@ declare module "stream" {
|
|
|
1499
1499
|
* );
|
|
1500
1500
|
* ```
|
|
1501
1501
|
*
|
|
1502
|
-
* The `pipeline` API provides a `promise version
|
|
1502
|
+
* The `pipeline` API provides a [`promise version`](https://nodejs.org/docs/latest-v24.x/api/stream.html#streampipelinesource-transforms-destination-options).
|
|
1503
1503
|
*
|
|
1504
1504
|
* `stream.pipeline()` will call `stream.destroy(err)` on all streams except:
|
|
1505
1505
|
*
|
|
@@ -1518,9 +1518,9 @@ declare module "stream" {
|
|
|
1518
1518
|
* See the example below:
|
|
1519
1519
|
*
|
|
1520
1520
|
* ```js
|
|
1521
|
-
*
|
|
1522
|
-
*
|
|
1523
|
-
*
|
|
1521
|
+
* import fs from 'node:fs';
|
|
1522
|
+
* import http from 'node:http';
|
|
1523
|
+
* import { pipeline } from 'node:stream';
|
|
1524
1524
|
*
|
|
1525
1525
|
* const server = http.createServer((req, res) => {
|
|
1526
1526
|
* const fileStream = fs.createReadStream('./fileNotExist.txt');
|
|
@@ -1539,7 +1539,7 @@ declare module "stream" {
|
|
|
1539
1539
|
function pipeline<A extends PipelineSource<any>, B extends PipelineDestination<A, any>>(
|
|
1540
1540
|
source: A,
|
|
1541
1541
|
destination: B,
|
|
1542
|
-
callback
|
|
1542
|
+
callback: PipelineCallback<B>,
|
|
1543
1543
|
): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
|
|
1544
1544
|
function pipeline<
|
|
1545
1545
|
A extends PipelineSource<any>,
|
|
@@ -1549,7 +1549,7 @@ declare module "stream" {
|
|
|
1549
1549
|
source: A,
|
|
1550
1550
|
transform1: T1,
|
|
1551
1551
|
destination: B,
|
|
1552
|
-
callback
|
|
1552
|
+
callback: PipelineCallback<B>,
|
|
1553
1553
|
): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
|
|
1554
1554
|
function pipeline<
|
|
1555
1555
|
A extends PipelineSource<any>,
|
|
@@ -1561,7 +1561,7 @@ declare module "stream" {
|
|
|
1561
1561
|
transform1: T1,
|
|
1562
1562
|
transform2: T2,
|
|
1563
1563
|
destination: B,
|
|
1564
|
-
callback
|
|
1564
|
+
callback: PipelineCallback<B>,
|
|
1565
1565
|
): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
|
|
1566
1566
|
function pipeline<
|
|
1567
1567
|
A extends PipelineSource<any>,
|
|
@@ -1575,7 +1575,7 @@ declare module "stream" {
|
|
|
1575
1575
|
transform2: T2,
|
|
1576
1576
|
transform3: T3,
|
|
1577
1577
|
destination: B,
|
|
1578
|
-
callback
|
|
1578
|
+
callback: PipelineCallback<B>,
|
|
1579
1579
|
): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
|
|
1580
1580
|
function pipeline<
|
|
1581
1581
|
A extends PipelineSource<any>,
|
|
@@ -1591,11 +1591,11 @@ declare module "stream" {
|
|
|
1591
1591
|
transform3: T3,
|
|
1592
1592
|
transform4: T4,
|
|
1593
1593
|
destination: B,
|
|
1594
|
-
callback
|
|
1594
|
+
callback: PipelineCallback<B>,
|
|
1595
1595
|
): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
|
|
1596
1596
|
function pipeline(
|
|
1597
1597
|
streams: ReadonlyArray<NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream>,
|
|
1598
|
-
callback
|
|
1598
|
+
callback: (err: NodeJS.ErrnoException | null) => void,
|
|
1599
1599
|
): NodeJS.WritableStream;
|
|
1600
1600
|
function pipeline(
|
|
1601
1601
|
stream1: NodeJS.ReadableStream,
|
|
@@ -1672,28 +1672,33 @@ declare module "stream" {
|
|
|
1672
1672
|
...streams: Array<NodeJS.ReadWriteStream | NodeJS.WritableStream | PipelineOptions>
|
|
1673
1673
|
): Promise<void>;
|
|
1674
1674
|
}
|
|
1675
|
+
// TODO: this interface never existed; remove in next major
|
|
1675
1676
|
interface Pipe {
|
|
1676
1677
|
close(): void;
|
|
1677
1678
|
hasRef(): boolean;
|
|
1678
1679
|
ref(): void;
|
|
1679
1680
|
unref(): void;
|
|
1680
1681
|
}
|
|
1682
|
+
// TODO: these should all take webstream arguments
|
|
1681
1683
|
/**
|
|
1682
1684
|
* Returns whether the stream has encountered an error.
|
|
1683
1685
|
* @since v17.3.0, v16.14.0
|
|
1684
|
-
* @experimental
|
|
1685
1686
|
*/
|
|
1686
1687
|
function isErrored(stream: Readable | Writable | NodeJS.ReadableStream | NodeJS.WritableStream): boolean;
|
|
1687
1688
|
/**
|
|
1688
1689
|
* Returns whether the stream is readable.
|
|
1689
1690
|
* @since v17.4.0, v16.14.0
|
|
1690
|
-
* @
|
|
1691
|
+
* @returns Only returns `null` if `stream` is not a valid `Readable`, `Duplex` or `ReadableStream`.
|
|
1692
|
+
*/
|
|
1693
|
+
function isReadable(stream: Readable | NodeJS.ReadableStream): boolean | null;
|
|
1694
|
+
/**
|
|
1695
|
+
* Returns whether the stream is writable.
|
|
1696
|
+
* @since v20.0.0
|
|
1697
|
+
* @returns Only returns `null` if `stream` is not a valid `Writable`, `Duplex` or `WritableStream`.
|
|
1691
1698
|
*/
|
|
1692
|
-
function
|
|
1693
|
-
const promises: typeof streamPromises;
|
|
1694
|
-
const consumers: typeof streamConsumers;
|
|
1699
|
+
function isWritable(stream: Writable | NodeJS.WritableStream): boolean | null;
|
|
1695
1700
|
}
|
|
1696
|
-
export =
|
|
1701
|
+
export = Stream;
|
|
1697
1702
|
}
|
|
1698
1703
|
declare module "node:stream" {
|
|
1699
1704
|
import stream = require("stream");
|