@types/node 18.19.22 → 18.19.24

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.
Files changed (57) hide show
  1. node v18.19/README.md +1 -1
  2. node v18.19/crypto.d.ts +1 -1
  3. node v18.19/package.json +3 -10
  4. node v18.19/ts4.8/assert/strict.d.ts +0 -8
  5. node v18.19/ts4.8/assert.d.ts +0 -985
  6. node v18.19/ts4.8/async_hooks.d.ts +0 -522
  7. node v18.19/ts4.8/buffer.d.ts +0 -2353
  8. node v18.19/ts4.8/child_process.d.ts +0 -1544
  9. node v18.19/ts4.8/cluster.d.ts +0 -432
  10. node v18.19/ts4.8/console.d.ts +0 -412
  11. node v18.19/ts4.8/constants.d.ts +0 -19
  12. node v18.19/ts4.8/crypto.d.ts +0 -4457
  13. node v18.19/ts4.8/dgram.d.ts +0 -596
  14. node v18.19/ts4.8/diagnostics_channel.d.ts +0 -546
  15. node v18.19/ts4.8/dns/promises.d.ts +0 -381
  16. node v18.19/ts4.8/dns.d.ts +0 -809
  17. node v18.19/ts4.8/dom-events.d.ts +0 -122
  18. node v18.19/ts4.8/domain.d.ts +0 -170
  19. node v18.19/ts4.8/events.d.ts +0 -819
  20. node v18.19/ts4.8/fs/promises.d.ts +0 -1205
  21. node v18.19/ts4.8/fs.d.ts +0 -4231
  22. node v18.19/ts4.8/globals.d.ts +0 -377
  23. node v18.19/ts4.8/globals.global.d.ts +0 -1
  24. node v18.19/ts4.8/http.d.ts +0 -1803
  25. node v18.19/ts4.8/http2.d.ts +0 -2386
  26. node v18.19/ts4.8/https.d.ts +0 -544
  27. node v18.19/ts4.8/index.d.ts +0 -88
  28. node v18.19/ts4.8/inspector.d.ts +0 -2739
  29. node v18.19/ts4.8/module.d.ts +0 -298
  30. node v18.19/ts4.8/net.d.ts +0 -918
  31. node v18.19/ts4.8/os.d.ts +0 -473
  32. node v18.19/ts4.8/path.d.ts +0 -191
  33. node v18.19/ts4.8/perf_hooks.d.ts +0 -626
  34. node v18.19/ts4.8/process.d.ts +0 -1548
  35. node v18.19/ts4.8/punycode.d.ts +0 -117
  36. node v18.19/ts4.8/querystring.d.ts +0 -141
  37. node v18.19/ts4.8/readline/promises.d.ts +0 -143
  38. node v18.19/ts4.8/readline.d.ts +0 -666
  39. node v18.19/ts4.8/repl.d.ts +0 -430
  40. node v18.19/ts4.8/stream/consumers.d.ts +0 -12
  41. node v18.19/ts4.8/stream/promises.d.ts +0 -83
  42. node v18.19/ts4.8/stream/web.d.ts +0 -352
  43. node v18.19/ts4.8/stream.d.ts +0 -1731
  44. node v18.19/ts4.8/string_decoder.d.ts +0 -67
  45. node v18.19/ts4.8/test.d.ts +0 -1113
  46. node v18.19/ts4.8/timers/promises.d.ts +0 -93
  47. node v18.19/ts4.8/timers.d.ts +0 -126
  48. node v18.19/ts4.8/tls.d.ts +0 -1203
  49. node v18.19/ts4.8/trace_events.d.ts +0 -171
  50. node v18.19/ts4.8/tty.d.ts +0 -206
  51. node v18.19/ts4.8/url.d.ts +0 -954
  52. node v18.19/ts4.8/util.d.ts +0 -2075
  53. node v18.19/ts4.8/v8.d.ts +0 -753
  54. node v18.19/ts4.8/vm.d.ts +0 -667
  55. node v18.19/ts4.8/wasi.d.ts +0 -158
  56. node v18.19/ts4.8/worker_threads.d.ts +0 -692
  57. node v18.19/ts4.8/zlib.d.ts +0 -517
@@ -1,1731 +0,0 @@
1
- /**
2
- * A stream is an abstract interface for working with streaming data in Node.js.
3
- * The `stream` module provides an API for implementing the stream interface.
4
- *
5
- * There are many stream objects provided by Node.js. For instance, a `request to an HTTP server` and `process.stdout` are both stream instances.
6
- *
7
- * Streams can be readable, writable, or both. All streams are instances of `EventEmitter`.
8
- *
9
- * To access the `stream` module:
10
- *
11
- * ```js
12
- * const stream = require('stream');
13
- * ```
14
- *
15
- * The `stream` module is useful for creating new types of stream instances. It is
16
- * usually not necessary to use the `stream` module to consume streams.
17
- * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/stream.js)
18
- */
19
- declare module "stream" {
20
- import { Abortable, EventEmitter } from "node:events";
21
- import { Blob as NodeBlob } from "node:buffer";
22
- import * as streamPromises from "node:stream/promises";
23
- import * as streamConsumers from "node:stream/consumers";
24
- import * as streamWeb from "node:stream/web";
25
-
26
- type ComposeFnParam = (source: any) => void;
27
-
28
- class internal extends EventEmitter {
29
- pipe<T extends NodeJS.WritableStream>(
30
- destination: T,
31
- options?: {
32
- end?: boolean | undefined;
33
- },
34
- ): T;
35
- compose<T extends NodeJS.ReadableStream>(
36
- stream: T | ComposeFnParam | Iterable<T> | AsyncIterable<T>,
37
- options?: { signal: AbortSignal },
38
- ): T;
39
- }
40
- namespace internal {
41
- class Stream extends internal {
42
- constructor(opts?: ReadableOptions);
43
- }
44
- interface StreamOptions<T extends Stream> extends Abortable {
45
- emitClose?: boolean | undefined;
46
- highWaterMark?: number | undefined;
47
- objectMode?: boolean | undefined;
48
- construct?(this: T, callback: (error?: Error | null) => void): void;
49
- destroy?(this: T, error: Error | null, callback: (error?: Error | null) => void): void;
50
- autoDestroy?: boolean | undefined;
51
- }
52
- interface ReadableOptions extends StreamOptions<Readable> {
53
- encoding?: BufferEncoding | undefined;
54
- read?(this: Readable, size: number): void;
55
- }
56
- interface ArrayOptions {
57
- /** the maximum concurrent invocations of `fn` to call on the stream at once. **Default: 1**. */
58
- concurrency?: number;
59
- /** allows destroying the stream if the signal is aborted. */
60
- signal?: AbortSignal;
61
- }
62
- /**
63
- * @since v0.9.4
64
- */
65
- class Readable extends Stream implements NodeJS.ReadableStream {
66
- /**
67
- * A utility method for creating Readable Streams out of iterators.
68
- */
69
- static from(iterable: Iterable<any> | AsyncIterable<any>, options?: ReadableOptions): Readable;
70
- /**
71
- * A utility method for creating a `Readable` from a web `ReadableStream`.
72
- * @since v17.0.0
73
- * @experimental
74
- */
75
- static fromWeb(
76
- readableStream: streamWeb.ReadableStream,
77
- options?: Pick<ReadableOptions, "encoding" | "highWaterMark" | "objectMode" | "signal">,
78
- ): Readable;
79
- /**
80
- * Returns whether the stream has been read from or cancelled.
81
- * @since v16.8.0
82
- */
83
- static isDisturbed(stream: Readable | NodeJS.ReadableStream): boolean;
84
- /**
85
- * A utility method for creating a web `ReadableStream` from a `Readable`.
86
- * @since v17.0.0
87
- * @experimental
88
- */
89
- static toWeb(streamReadable: Readable): streamWeb.ReadableStream;
90
- /**
91
- * Returns whether the stream was destroyed or errored before emitting `'end'`.
92
- * @since v16.8.0
93
- * @experimental
94
- */
95
- readonly readableAborted: boolean;
96
- /**
97
- * Is `true` if it is safe to call `readable.read()`, which means
98
- * the stream has not been destroyed or emitted `'error'` or `'end'`.
99
- * @since v11.4.0
100
- */
101
- readable: boolean;
102
- /**
103
- * Returns whether `'data'` has been emitted.
104
- * @since v16.7.0, v14.18.0
105
- * @experimental
106
- */
107
- readonly readableDidRead: boolean;
108
- /**
109
- * Getter for the property `encoding` of a given `Readable` stream. The `encoding`property can be set using the `readable.setEncoding()` method.
110
- * @since v12.7.0
111
- */
112
- readonly readableEncoding: BufferEncoding | null;
113
- /**
114
- * Becomes `true` when `'end'` event is emitted.
115
- * @since v12.9.0
116
- */
117
- readonly readableEnded: boolean;
118
- /**
119
- * This property reflects the current state of a `Readable` stream as described
120
- * in the `Three states` section.
121
- * @since v9.4.0
122
- */
123
- readonly readableFlowing: boolean | null;
124
- /**
125
- * Returns the value of `highWaterMark` passed when creating this `Readable`.
126
- * @since v9.3.0
127
- */
128
- readonly readableHighWaterMark: number;
129
- /**
130
- * This property contains the number of bytes (or objects) in the queue
131
- * ready to be read. The value provides introspection data regarding
132
- * the status of the `highWaterMark`.
133
- * @since v9.4.0
134
- */
135
- readonly readableLength: number;
136
- /**
137
- * Getter for the property `objectMode` of a given `Readable` stream.
138
- * @since v12.3.0
139
- */
140
- readonly readableObjectMode: boolean;
141
- /**
142
- * Is `true` after `readable.destroy()` has been called.
143
- * @since v8.0.0
144
- */
145
- destroyed: boolean;
146
- /**
147
- * Is true after 'close' has been emitted.
148
- * @since v18.0.0
149
- */
150
- readonly closed: boolean;
151
- /**
152
- * Returns error if the stream has been destroyed with an error.
153
- * @since v18.0.0
154
- */
155
- readonly errored: Error | null;
156
- constructor(opts?: ReadableOptions);
157
- _construct?(callback: (error?: Error | null) => void): void;
158
- _read(size: number): void;
159
- /**
160
- * The `readable.read()` method reads data out of the internal buffer and
161
- * returns it. If no data is available to be read, `null` is returned. By default,
162
- * the data is returned as a `Buffer` object unless an encoding has been
163
- * specified using the `readable.setEncoding()` method or the stream is operating
164
- * in object mode.
165
- *
166
- * 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
167
- * case all of the data remaining in the internal
168
- * buffer will be returned.
169
- *
170
- * If the `size` argument is not specified, all of the data contained in the
171
- * internal buffer will be returned.
172
- *
173
- * The `size` argument must be less than or equal to 1 GiB.
174
- *
175
- * The `readable.read()` method should only be called on `Readable` streams
176
- * operating in paused mode. In flowing mode, `readable.read()` is called
177
- * automatically until the internal buffer is fully drained.
178
- *
179
- * ```js
180
- * const readable = getReadableStreamSomehow();
181
- *
182
- * // 'readable' may be triggered multiple times as data is buffered in
183
- * readable.on('readable', () => {
184
- * let chunk;
185
- * console.log('Stream is readable (new data received in buffer)');
186
- * // Use a loop to make sure we read all currently available data
187
- * while (null !== (chunk = readable.read())) {
188
- * console.log(`Read ${chunk.length} bytes of data...`);
189
- * }
190
- * });
191
- *
192
- * // 'end' will be triggered once when there is no more data available
193
- * readable.on('end', () => {
194
- * console.log('Reached end of stream.');
195
- * });
196
- * ```
197
- *
198
- * Each call to `readable.read()` returns a chunk of data, or `null`. The chunks
199
- * are not concatenated. A `while` loop is necessary to consume all data
200
- * currently in the buffer. When reading a large file `.read()` may return `null`,
201
- * having consumed all buffered content so far, but there is still more data to
202
- * come not yet buffered. In this case a new `'readable'` event will be emitted
203
- * when there is more data in the buffer. Finally the `'end'` event will be
204
- * emitted when there is no more data to come.
205
- *
206
- * Therefore to read a file's whole contents from a `readable`, it is necessary
207
- * to collect chunks across multiple `'readable'` events:
208
- *
209
- * ```js
210
- * const chunks = [];
211
- *
212
- * readable.on('readable', () => {
213
- * let chunk;
214
- * while (null !== (chunk = readable.read())) {
215
- * chunks.push(chunk);
216
- * }
217
- * });
218
- *
219
- * readable.on('end', () => {
220
- * const content = chunks.join('');
221
- * });
222
- * ```
223
- *
224
- * A `Readable` stream in object mode will always return a single item from
225
- * a call to `readable.read(size)`, regardless of the value of the`size` argument.
226
- *
227
- * If the `readable.read()` method returns a chunk of data, a `'data'` event will
228
- * also be emitted.
229
- *
230
- * Calling {@link read} after the `'end'` event has
231
- * been emitted will return `null`. No runtime error will be raised.
232
- * @since v0.9.4
233
- * @param size Optional argument to specify how much data to read.
234
- */
235
- read(size?: number): any;
236
- /**
237
- * The `readable.setEncoding()` method sets the character encoding for
238
- * data read from the `Readable` stream.
239
- *
240
- * By default, no encoding is assigned and stream data will be returned as`Buffer` objects. Setting an encoding causes the stream data
241
- * to be returned as strings of the specified encoding rather than as `Buffer`objects. For instance, calling `readable.setEncoding('utf8')` will cause the
242
- * 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
243
- * string format.
244
- *
245
- * The `Readable` stream will properly handle multi-byte characters delivered
246
- * through the stream that would otherwise become improperly decoded if simply
247
- * pulled from the stream as `Buffer` objects.
248
- *
249
- * ```js
250
- * const readable = getReadableStreamSomehow();
251
- * readable.setEncoding('utf8');
252
- * readable.on('data', (chunk) => {
253
- * assert.equal(typeof chunk, 'string');
254
- * console.log('Got %d characters of string data:', chunk.length);
255
- * });
256
- * ```
257
- * @since v0.9.4
258
- * @param encoding The encoding to use.
259
- */
260
- setEncoding(encoding: BufferEncoding): this;
261
- /**
262
- * The `readable.pause()` method will cause a stream in flowing mode to stop
263
- * emitting `'data'` events, switching out of flowing mode. Any data that
264
- * becomes available will remain in the internal buffer.
265
- *
266
- * ```js
267
- * const readable = getReadableStreamSomehow();
268
- * readable.on('data', (chunk) => {
269
- * console.log(`Received ${chunk.length} bytes of data.`);
270
- * readable.pause();
271
- * console.log('There will be no additional data for 1 second.');
272
- * setTimeout(() => {
273
- * console.log('Now data will start flowing again.');
274
- * readable.resume();
275
- * }, 1000);
276
- * });
277
- * ```
278
- *
279
- * The `readable.pause()` method has no effect if there is a `'readable'`event listener.
280
- * @since v0.9.4
281
- */
282
- pause(): this;
283
- /**
284
- * The `readable.resume()` method causes an explicitly paused `Readable` stream to
285
- * resume emitting `'data'` events, switching the stream into flowing mode.
286
- *
287
- * The `readable.resume()` method can be used to fully consume the data from a
288
- * stream without actually processing any of that data:
289
- *
290
- * ```js
291
- * getReadableStreamSomehow()
292
- * .resume()
293
- * .on('end', () => {
294
- * console.log('Reached the end, but did not read anything.');
295
- * });
296
- * ```
297
- *
298
- * The `readable.resume()` method has no effect if there is a `'readable'`event listener.
299
- * @since v0.9.4
300
- */
301
- resume(): this;
302
- /**
303
- * 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
304
- * typical cases, there will be no reason to
305
- * use this method directly.
306
- *
307
- * ```js
308
- * const readable = new stream.Readable();
309
- *
310
- * readable.isPaused(); // === false
311
- * readable.pause();
312
- * readable.isPaused(); // === true
313
- * readable.resume();
314
- * readable.isPaused(); // === false
315
- * ```
316
- * @since v0.11.14
317
- */
318
- isPaused(): boolean;
319
- /**
320
- * The `readable.unpipe()` method detaches a `Writable` stream previously attached
321
- * using the {@link pipe} method.
322
- *
323
- * If the `destination` is not specified, then _all_ pipes are detached.
324
- *
325
- * If the `destination` is specified, but no pipe is set up for it, then
326
- * the method does nothing.
327
- *
328
- * ```js
329
- * const fs = require('fs');
330
- * const readable = getReadableStreamSomehow();
331
- * const writable = fs.createWriteStream('file.txt');
332
- * // All the data from readable goes into 'file.txt',
333
- * // but only for the first second.
334
- * readable.pipe(writable);
335
- * setTimeout(() => {
336
- * console.log('Stop writing to file.txt.');
337
- * readable.unpipe(writable);
338
- * console.log('Manually close the file stream.');
339
- * writable.end();
340
- * }, 1000);
341
- * ```
342
- * @since v0.9.4
343
- * @param destination Optional specific stream to unpipe
344
- */
345
- unpipe(destination?: NodeJS.WritableStream): this;
346
- /**
347
- * Passing `chunk` as `null` signals the end of the stream (EOF) and behaves the
348
- * same as `readable.push(null)`, after which no more data can be written. The EOF
349
- * signal is put at the end of the buffer and any buffered data will still be
350
- * flushed.
351
- *
352
- * The `readable.unshift()` method pushes a chunk of data back into the internal
353
- * buffer. This is useful in certain situations where a stream is being consumed by
354
- * code that needs to "un-consume" some amount of data that it has optimistically
355
- * pulled out of the source, so that the data can be passed on to some other party.
356
- *
357
- * The `stream.unshift(chunk)` method cannot be called after the `'end'` event
358
- * has been emitted or a runtime error will be thrown.
359
- *
360
- * Developers using `stream.unshift()` often should consider switching to
361
- * use of a `Transform` stream instead. See the `API for stream implementers` section for more information.
362
- *
363
- * ```js
364
- * // Pull off a header delimited by \n\n.
365
- * // Use unshift() if we get too much.
366
- * // Call the callback with (error, header, stream).
367
- * const { StringDecoder } = require('string_decoder');
368
- * function parseHeader(stream, callback) {
369
- * stream.on('error', callback);
370
- * stream.on('readable', onReadable);
371
- * const decoder = new StringDecoder('utf8');
372
- * let header = '';
373
- * function onReadable() {
374
- * let chunk;
375
- * while (null !== (chunk = stream.read())) {
376
- * const str = decoder.write(chunk);
377
- * if (str.includes('\n\n')) {
378
- * // Found the header boundary.
379
- * const split = str.split(/\n\n/);
380
- * header += split.shift();
381
- * const remaining = split.join('\n\n');
382
- * const buf = Buffer.from(remaining, 'utf8');
383
- * stream.removeListener('error', callback);
384
- * // Remove the 'readable' listener before unshifting.
385
- * stream.removeListener('readable', onReadable);
386
- * if (buf.length)
387
- * stream.unshift(buf);
388
- * // Now the body of the message can be read from the stream.
389
- * callback(null, header, stream);
390
- * return;
391
- * }
392
- * // Still reading the header.
393
- * header += str;
394
- * }
395
- * }
396
- * }
397
- * ```
398
- *
399
- * Unlike {@link push}, `stream.unshift(chunk)` will not
400
- * end the reading process by resetting the internal reading state of the stream.
401
- * This can cause unexpected results if `readable.unshift()` is called during a
402
- * read (i.e. from within a {@link _read} implementation on a
403
- * custom stream). Following the call to `readable.unshift()` with an immediate {@link push} will reset the reading state appropriately,
404
- * however it is best to simply avoid calling `readable.unshift()` while in the
405
- * process of performing a read.
406
- * @since v0.9.11
407
- * @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
408
- * streams, `chunk` may be any JavaScript value.
409
- * @param encoding Encoding of string chunks. Must be a valid `Buffer` encoding, such as `'utf8'` or `'ascii'`.
410
- */
411
- unshift(chunk: any, encoding?: BufferEncoding): void;
412
- /**
413
- * Prior to Node.js 0.10, streams did not implement the entire `stream` module API
414
- * as it is currently defined. (See `Compatibility` for more information.)
415
- *
416
- * 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`
417
- * stream that uses
418
- * the old stream as its data source.
419
- *
420
- * It will rarely be necessary to use `readable.wrap()` but the method has been
421
- * provided as a convenience for interacting with older Node.js applications and
422
- * libraries.
423
- *
424
- * ```js
425
- * const { OldReader } = require('./old-api-module.js');
426
- * const { Readable } = require('stream');
427
- * const oreader = new OldReader();
428
- * const myReader = new Readable().wrap(oreader);
429
- *
430
- * myReader.on('readable', () => {
431
- * myReader.read(); // etc.
432
- * });
433
- * ```
434
- * @since v0.9.4
435
- * @param stream An "old style" readable stream
436
- */
437
- wrap(stream: NodeJS.ReadableStream): this;
438
- push(chunk: any, encoding?: BufferEncoding): boolean;
439
- /**
440
- * The iterator created by this method gives users the option to cancel the destruction
441
- * of the stream if the `for await...of` loop is exited by `return`, `break`, or `throw`,
442
- * or if the iterator should destroy the stream if the stream emitted an error during iteration.
443
- * @since v16.3.0
444
- * @param options.destroyOnReturn When set to `false`, calling `return` on the async iterator,
445
- * or exiting a `for await...of` iteration using a `break`, `return`, or `throw` will not destroy the stream.
446
- * **Default: `true`**.
447
- */
448
- iterator(options?: { destroyOnReturn?: boolean }): AsyncIterableIterator<any>;
449
- /**
450
- * This method allows mapping over the stream. The *fn* function will be called for every chunk in the stream.
451
- * If the *fn* function returns a promise - that promise will be `await`ed before being passed to the result stream.
452
- * @since v17.4.0, v16.14.0
453
- * @param fn a function to map over every chunk in the stream. Async or not.
454
- * @returns a stream mapped with the function *fn*.
455
- */
456
- map(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => any, options?: ArrayOptions): Readable;
457
- /**
458
- * This method allows filtering the stream. For each chunk in the stream the *fn* function will be called
459
- * and if it returns a truthy value, the chunk will be passed to the result stream.
460
- * If the *fn* function returns a promise - that promise will be `await`ed.
461
- * @since v17.4.0, v16.14.0
462
- * @param fn a function to filter chunks from the stream. Async or not.
463
- * @returns a stream filtered with the predicate *fn*.
464
- */
465
- filter(
466
- fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
467
- options?: ArrayOptions,
468
- ): Readable;
469
- /**
470
- * This method allows iterating a stream. For each chunk in the stream the *fn* function will be called.
471
- * If the *fn* function returns a promise - that promise will be `await`ed.
472
- *
473
- * This method is different from `for await...of` loops in that it can optionally process chunks concurrently.
474
- * In addition, a `forEach` iteration can only be stopped by having passed a `signal` option
475
- * and aborting the related AbortController while `for await...of` can be stopped with `break` or `return`.
476
- * In either case the stream will be destroyed.
477
- *
478
- * This method is different from listening to the `'data'` event in that it uses the `readable` event
479
- * in the underlying machinary and can limit the number of concurrent *fn* calls.
480
- * @since v17.5.0
481
- * @param fn a function to call on each chunk of the stream. Async or not.
482
- * @returns a promise for when the stream has finished.
483
- */
484
- forEach(
485
- fn: (data: any, options?: Pick<ArrayOptions, "signal">) => void | Promise<void>,
486
- options?: ArrayOptions,
487
- ): Promise<void>;
488
- /**
489
- * This method allows easily obtaining the contents of a stream.
490
- *
491
- * As this method reads the entire stream into memory, it negates the benefits of streams. It's intended
492
- * for interoperability and convenience, not as the primary way to consume streams.
493
- * @since v17.5.0
494
- * @returns a promise containing an array with the contents of the stream.
495
- */
496
- toArray(options?: Pick<ArrayOptions, "signal">): Promise<any[]>;
497
- /**
498
- * This method is similar to `Array.prototype.some` and calls *fn* on each chunk in the stream
499
- * until the awaited return value is `true` (or any truthy value). Once an *fn* call on a chunk
500
- * `await`ed return value is truthy, the stream is destroyed and the promise is fulfilled with `true`.
501
- * If none of the *fn* calls on the chunks return a truthy value, the promise is fulfilled with `false`.
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 at least one of the chunks.
505
- */
506
- some(
507
- fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
508
- options?: ArrayOptions,
509
- ): Promise<boolean>;
510
- /**
511
- * This method is similar to `Array.prototype.find` and calls *fn* on each chunk in the stream
512
- * to find a chunk with a truthy value for *fn*. Once an *fn* call's awaited return value is truthy,
513
- * the stream is destroyed and the promise is fulfilled with value for which *fn* returned a truthy value.
514
- * If all of the *fn* calls on the chunks return a falsy value, the promise is fulfilled with `undefined`.
515
- * @since v17.5.0
516
- * @param fn a function to call on each chunk of the stream. Async or not.
517
- * @returns a promise evaluating to the first chunk for which *fn* evaluated with a truthy value,
518
- * or `undefined` if no element was found.
519
- */
520
- find<T>(
521
- fn: (data: any, options?: Pick<ArrayOptions, "signal">) => data is T,
522
- options?: ArrayOptions,
523
- ): Promise<T | undefined>;
524
- find(
525
- fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
526
- options?: ArrayOptions,
527
- ): Promise<any>;
528
- /**
529
- * This method is similar to `Array.prototype.every` and calls *fn* on each chunk in the stream
530
- * to check if all awaited return values are truthy value for *fn*. Once an *fn* call on a chunk
531
- * `await`ed return value is falsy, the stream is destroyed and the promise is fulfilled with `false`.
532
- * If all of the *fn* calls on the chunks return a truthy value, the promise is fulfilled with `true`.
533
- * @since v17.5.0
534
- * @param fn a function to call on each chunk of the stream. Async or not.
535
- * @returns a promise evaluating to `true` if *fn* returned a truthy value for every one of the chunks.
536
- */
537
- every(
538
- fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
539
- options?: ArrayOptions,
540
- ): Promise<boolean>;
541
- /**
542
- * This method returns a new stream by applying the given callback to each chunk of the stream
543
- * and then flattening the result.
544
- *
545
- * It is possible to return a stream or another iterable or async iterable from *fn* and the result streams
546
- * will be merged (flattened) into the returned stream.
547
- * @since v17.5.0
548
- * @param fn a function to map over every chunk in the stream. May be async. May be a stream or generator.
549
- * @returns a stream flat-mapped with the function *fn*.
550
- */
551
- flatMap(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => any, options?: ArrayOptions): Readable;
552
- /**
553
- * This method returns a new stream with the first *limit* chunks dropped from the start.
554
- * @since v17.5.0
555
- * @param limit the number of chunks to drop from the readable.
556
- * @returns a stream with *limit* chunks dropped from the start.
557
- */
558
- drop(limit: number, options?: Pick<ArrayOptions, "signal">): Readable;
559
- /**
560
- * This method returns a new stream with the first *limit* chunks.
561
- * @since v17.5.0
562
- * @param limit the number of chunks to take from the readable.
563
- * @returns a stream with *limit* chunks taken.
564
- */
565
- take(limit: number, options?: Pick<ArrayOptions, "signal">): Readable;
566
- /**
567
- * This method returns a new stream with chunks of the underlying stream paired with a counter
568
- * in the form `[index, chunk]`. The first index value is `0` and it increases by 1 for each chunk produced.
569
- * @since v17.5.0
570
- * @returns a stream of indexed pairs.
571
- */
572
- asIndexedPairs(options?: Pick<ArrayOptions, "signal">): Readable;
573
- /**
574
- * This method calls *fn* on each chunk of the stream in order, passing it the result from the calculation
575
- * on the previous element. It returns a promise for the final value of the reduction.
576
- *
577
- * If no *initial* value is supplied the first chunk of the stream is used as the initial value.
578
- * If the stream is empty, the promise is rejected with a `TypeError` with the `ERR_INVALID_ARGS` code property.
579
- *
580
- * The reducer function iterates the stream element-by-element which means that there is no *concurrency* parameter
581
- * or parallelism. To perform a reduce concurrently, you can extract the async function to `readable.map` method.
582
- * @since v17.5.0
583
- * @param fn a reducer function to call over every chunk in the stream. Async or not.
584
- * @param initial the initial value to use in the reduction.
585
- * @returns a promise for the final value of the reduction.
586
- */
587
- reduce<T = any>(
588
- fn: (previous: any, data: any, options?: Pick<ArrayOptions, "signal">) => T,
589
- initial?: undefined,
590
- options?: Pick<ArrayOptions, "signal">,
591
- ): Promise<T>;
592
- reduce<T = any>(
593
- fn: (previous: T, data: any, options?: Pick<ArrayOptions, "signal">) => T,
594
- initial: T,
595
- options?: Pick<ArrayOptions, "signal">,
596
- ): Promise<T>;
597
- _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
598
- /**
599
- * Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'`event (unless `emitClose` is set to `false`). After this call, the readable
600
- * stream will release any internal resources and subsequent calls to `push()`will be ignored.
601
- *
602
- * Once `destroy()` has been called any further calls will be a no-op and no
603
- * further errors except from `_destroy()` may be emitted as `'error'`.
604
- *
605
- * Implementors should not override this method, but instead implement `readable._destroy()`.
606
- * @since v8.0.0
607
- * @param error Error which will be passed as payload in `'error'` event
608
- */
609
- destroy(error?: Error): this;
610
- /**
611
- * Event emitter
612
- * The defined events on documents including:
613
- * 1. close
614
- * 2. data
615
- * 3. end
616
- * 4. error
617
- * 5. pause
618
- * 6. readable
619
- * 7. resume
620
- */
621
- addListener(event: "close", listener: () => void): this;
622
- addListener(event: "data", listener: (chunk: any) => void): this;
623
- addListener(event: "end", listener: () => void): this;
624
- addListener(event: "error", listener: (err: Error) => void): this;
625
- addListener(event: "pause", listener: () => void): this;
626
- addListener(event: "readable", listener: () => void): this;
627
- addListener(event: "resume", listener: () => void): this;
628
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
629
- emit(event: "close"): boolean;
630
- emit(event: "data", chunk: any): boolean;
631
- emit(event: "end"): boolean;
632
- emit(event: "error", err: Error): boolean;
633
- emit(event: "pause"): boolean;
634
- emit(event: "readable"): boolean;
635
- emit(event: "resume"): boolean;
636
- emit(event: string | symbol, ...args: any[]): boolean;
637
- on(event: "close", listener: () => void): this;
638
- on(event: "data", listener: (chunk: any) => void): this;
639
- on(event: "end", listener: () => void): this;
640
- on(event: "error", listener: (err: Error) => void): this;
641
- on(event: "pause", listener: () => void): this;
642
- on(event: "readable", listener: () => void): this;
643
- on(event: "resume", listener: () => void): this;
644
- on(event: string | symbol, listener: (...args: any[]) => void): this;
645
- once(event: "close", listener: () => void): this;
646
- once(event: "data", listener: (chunk: any) => void): this;
647
- once(event: "end", listener: () => void): this;
648
- once(event: "error", listener: (err: Error) => void): this;
649
- once(event: "pause", listener: () => void): this;
650
- once(event: "readable", listener: () => void): this;
651
- once(event: "resume", listener: () => void): this;
652
- once(event: string | symbol, listener: (...args: any[]) => void): this;
653
- prependListener(event: "close", listener: () => void): this;
654
- prependListener(event: "data", listener: (chunk: any) => void): this;
655
- prependListener(event: "end", listener: () => void): this;
656
- prependListener(event: "error", listener: (err: Error) => void): this;
657
- prependListener(event: "pause", listener: () => void): this;
658
- prependListener(event: "readable", listener: () => void): this;
659
- prependListener(event: "resume", listener: () => void): this;
660
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
661
- prependOnceListener(event: "close", listener: () => void): this;
662
- prependOnceListener(event: "data", listener: (chunk: any) => void): this;
663
- prependOnceListener(event: "end", listener: () => void): this;
664
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
665
- prependOnceListener(event: "pause", listener: () => void): this;
666
- prependOnceListener(event: "readable", listener: () => void): this;
667
- prependOnceListener(event: "resume", listener: () => void): this;
668
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
669
- removeListener(event: "close", listener: () => void): this;
670
- removeListener(event: "data", listener: (chunk: any) => void): this;
671
- removeListener(event: "end", listener: () => void): this;
672
- removeListener(event: "error", listener: (err: Error) => void): this;
673
- removeListener(event: "pause", listener: () => void): this;
674
- removeListener(event: "readable", listener: () => void): this;
675
- removeListener(event: "resume", listener: () => void): this;
676
- removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
677
- [Symbol.asyncIterator](): AsyncIterableIterator<any>;
678
- /**
679
- * Calls `readable.destroy()` with an `AbortError` and returns a promise that fulfills when the stream is finished.
680
- * @since v18.18.0
681
- */
682
- [Symbol.asyncDispose](): Promise<void>;
683
- }
684
- interface WritableOptions extends StreamOptions<Writable> {
685
- decodeStrings?: boolean | undefined;
686
- defaultEncoding?: BufferEncoding | undefined;
687
- write?(
688
- this: Writable,
689
- chunk: any,
690
- encoding: BufferEncoding,
691
- callback: (error?: Error | null) => void,
692
- ): void;
693
- writev?(
694
- this: Writable,
695
- chunks: Array<{
696
- chunk: any;
697
- encoding: BufferEncoding;
698
- }>,
699
- callback: (error?: Error | null) => void,
700
- ): void;
701
- final?(this: Writable, callback: (error?: Error | null) => void): void;
702
- }
703
- /**
704
- * @since v0.9.4
705
- */
706
- class Writable extends Stream implements NodeJS.WritableStream {
707
- /**
708
- * A utility method for creating a `Writable` from a web `WritableStream`.
709
- * @since v17.0.0
710
- * @experimental
711
- */
712
- static fromWeb(
713
- writableStream: streamWeb.WritableStream,
714
- options?: Pick<WritableOptions, "decodeStrings" | "highWaterMark" | "objectMode" | "signal">,
715
- ): Writable;
716
- /**
717
- * A utility method for creating a web `WritableStream` from a `Writable`.
718
- * @since v17.0.0
719
- * @experimental
720
- */
721
- static toWeb(streamWritable: Writable): streamWeb.WritableStream;
722
- /**
723
- * Is `true` if it is safe to call `writable.write()`, which means
724
- * the stream has not been destroyed, errored or ended.
725
- * @since v11.4.0
726
- */
727
- readonly writable: boolean;
728
- /**
729
- * Is `true` after `writable.end()` has been called. This property
730
- * does not indicate whether the data has been flushed, for this use `writable.writableFinished` instead.
731
- * @since v12.9.0
732
- */
733
- readonly writableEnded: boolean;
734
- /**
735
- * Is set to `true` immediately before the `'finish'` event is emitted.
736
- * @since v12.6.0
737
- */
738
- readonly writableFinished: boolean;
739
- /**
740
- * Return the value of `highWaterMark` passed when creating this `Writable`.
741
- * @since v9.3.0
742
- */
743
- readonly writableHighWaterMark: number;
744
- /**
745
- * This property contains the number of bytes (or objects) in the queue
746
- * ready to be written. The value provides introspection data regarding
747
- * the status of the `highWaterMark`.
748
- * @since v9.4.0
749
- */
750
- readonly writableLength: number;
751
- /**
752
- * Getter for the property `objectMode` of a given `Writable` stream.
753
- * @since v12.3.0
754
- */
755
- readonly writableObjectMode: boolean;
756
- /**
757
- * Number of times `writable.uncork()` needs to be
758
- * called in order to fully uncork the stream.
759
- * @since v13.2.0, v12.16.0
760
- */
761
- readonly writableCorked: number;
762
- /**
763
- * Is `true` after `writable.destroy()` has been called.
764
- * @since v8.0.0
765
- */
766
- destroyed: boolean;
767
- /**
768
- * Is true after 'close' has been emitted.
769
- * @since v18.0.0
770
- */
771
- readonly closed: boolean;
772
- /**
773
- * Returns error if the stream has been destroyed with an error.
774
- * @since v18.0.0
775
- */
776
- readonly errored: Error | null;
777
- /**
778
- * Is `true` if the stream's buffer has been full and stream will emit 'drain'.
779
- * @since v15.2.0, v14.17.0
780
- */
781
- readonly writableNeedDrain: boolean;
782
- constructor(opts?: WritableOptions);
783
- _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
784
- _writev?(
785
- chunks: Array<{
786
- chunk: any;
787
- encoding: BufferEncoding;
788
- }>,
789
- callback: (error?: Error | null) => void,
790
- ): void;
791
- _construct?(callback: (error?: Error | null) => void): void;
792
- _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
793
- _final(callback: (error?: Error | null) => void): void;
794
- /**
795
- * The `writable.write()` method writes some data to the stream, and calls the
796
- * supplied `callback` once the data has been fully handled. If an error
797
- * occurs, the `callback` will be called with the error as its
798
- * first argument. The `callback` is called asynchronously and before `'error'` is
799
- * emitted.
800
- *
801
- * The return value is `true` if the internal buffer is less than the`highWaterMark` configured when the stream was created after admitting `chunk`.
802
- * If `false` is returned, further attempts to write data to the stream should
803
- * stop until the `'drain'` event is emitted.
804
- *
805
- * While a stream is not draining, calls to `write()` will buffer `chunk`, and
806
- * return false. Once all currently buffered chunks are drained (accepted for
807
- * delivery by the operating system), the `'drain'` event will be emitted.
808
- * Once `write()` returns false, do not write more chunks
809
- * until the `'drain'` event is emitted. While calling `write()` on a stream that
810
- * is not draining is allowed, Node.js will buffer all written chunks until
811
- * maximum memory usage occurs, at which point it will abort unconditionally.
812
- * Even before it aborts, high memory usage will cause poor garbage collector
813
- * performance and high RSS (which is not typically released back to the system,
814
- * even after the memory is no longer required). Since TCP sockets may never
815
- * drain if the remote peer does not read the data, writing a socket that is
816
- * not draining may lead to a remotely exploitable vulnerability.
817
- *
818
- * Writing data while the stream is not draining is particularly
819
- * problematic for a `Transform`, because the `Transform` streams are paused
820
- * by default until they are piped or a `'data'` or `'readable'` event handler
821
- * is added.
822
- *
823
- * If the data to be written can be generated or fetched on demand, it is
824
- * recommended to encapsulate the logic into a `Readable` and use {@link pipe}. However, if calling `write()` is preferred, it is
825
- * possible to respect backpressure and avoid memory issues using the `'drain'` event:
826
- *
827
- * ```js
828
- * function write(data, cb) {
829
- * if (!stream.write(data)) {
830
- * stream.once('drain', cb);
831
- * } else {
832
- * process.nextTick(cb);
833
- * }
834
- * }
835
- *
836
- * // Wait for cb to be called before doing any other write.
837
- * write('hello', () => {
838
- * console.log('Write completed, do more writes now.');
839
- * });
840
- * ```
841
- *
842
- * A `Writable` stream in object mode will always ignore the `encoding` argument.
843
- * @since v0.9.4
844
- * @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
845
- * JavaScript value other than `null`.
846
- * @param [encoding='utf8'] The encoding, if `chunk` is a string.
847
- * @param callback Callback for when this chunk of data is flushed.
848
- * @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`.
849
- */
850
- write(chunk: any, callback?: (error: Error | null | undefined) => void): boolean;
851
- write(chunk: any, encoding: BufferEncoding, callback?: (error: Error | null | undefined) => void): boolean;
852
- /**
853
- * The `writable.setDefaultEncoding()` method sets the default `encoding` for a `Writable` stream.
854
- * @since v0.11.15
855
- * @param encoding The new default encoding
856
- */
857
- setDefaultEncoding(encoding: BufferEncoding): this;
858
- /**
859
- * Calling the `writable.end()` method signals that no more data will be written
860
- * to the `Writable`. The optional `chunk` and `encoding` arguments allow one
861
- * final additional chunk of data to be written immediately before closing the
862
- * stream.
863
- *
864
- * Calling the {@link write} method after calling {@link end} will raise an error.
865
- *
866
- * ```js
867
- * // Write 'hello, ' and then end with 'world!'.
868
- * const fs = require('fs');
869
- * const file = fs.createWriteStream('example.txt');
870
- * file.write('hello, ');
871
- * file.end('world!');
872
- * // Writing more now is not allowed!
873
- * ```
874
- * @since v0.9.4
875
- * @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
876
- * JavaScript value other than `null`.
877
- * @param encoding The encoding if `chunk` is a string
878
- * @param callback Callback for when the stream is finished.
879
- */
880
- end(cb?: () => void): this;
881
- end(chunk: any, cb?: () => void): this;
882
- end(chunk: any, encoding: BufferEncoding, cb?: () => void): this;
883
- /**
884
- * The `writable.cork()` method forces all written data to be buffered in memory.
885
- * The buffered data will be flushed when either the {@link uncork} or {@link end} methods are called.
886
- *
887
- * The primary intent of `writable.cork()` is to accommodate a situation in which
888
- * several small chunks are written to the stream in rapid succession. Instead of
889
- * immediately forwarding them to the underlying destination, `writable.cork()`buffers all the chunks until `writable.uncork()` is called, which will pass them
890
- * all to `writable._writev()`, if present. This prevents a head-of-line blocking
891
- * situation where data is being buffered while waiting for the first small chunk
892
- * to be processed. However, use of `writable.cork()` without implementing`writable._writev()` may have an adverse effect on throughput.
893
- *
894
- * See also: `writable.uncork()`, `writable._writev()`.
895
- * @since v0.11.2
896
- */
897
- cork(): void;
898
- /**
899
- * The `writable.uncork()` method flushes all data buffered since {@link cork} was called.
900
- *
901
- * When using `writable.cork()` and `writable.uncork()` to manage the buffering
902
- * 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
903
- * loop phase.
904
- *
905
- * ```js
906
- * stream.cork();
907
- * stream.write('some ');
908
- * stream.write('data ');
909
- * process.nextTick(() => stream.uncork());
910
- * ```
911
- *
912
- * If the `writable.cork()` method is called multiple times on a stream, the
913
- * same number of calls to `writable.uncork()` must be called to flush the buffered
914
- * data.
915
- *
916
- * ```js
917
- * stream.cork();
918
- * stream.write('some ');
919
- * stream.cork();
920
- * stream.write('data ');
921
- * process.nextTick(() => {
922
- * stream.uncork();
923
- * // The data will not be flushed until uncork() is called a second time.
924
- * stream.uncork();
925
- * });
926
- * ```
927
- *
928
- * See also: `writable.cork()`.
929
- * @since v0.11.2
930
- */
931
- uncork(): void;
932
- /**
933
- * Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'`event (unless `emitClose` is set to `false`). After this call, the writable
934
- * stream has ended and subsequent calls to `write()` or `end()` will result in
935
- * an `ERR_STREAM_DESTROYED` error.
936
- * 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.
937
- * Use `end()` instead of destroy if data should flush before close, or wait for
938
- * the `'drain'` event before destroying the stream.
939
- *
940
- * Once `destroy()` has been called any further calls will be a no-op and no
941
- * further errors except from `_destroy()` may be emitted as `'error'`.
942
- *
943
- * Implementors should not override this method,
944
- * but instead implement `writable._destroy()`.
945
- * @since v8.0.0
946
- * @param error Optional, an error to emit with `'error'` event.
947
- */
948
- destroy(error?: Error): this;
949
- /**
950
- * Event emitter
951
- * The defined events on documents including:
952
- * 1. close
953
- * 2. drain
954
- * 3. error
955
- * 4. finish
956
- * 5. pipe
957
- * 6. unpipe
958
- */
959
- addListener(event: "close", listener: () => void): this;
960
- addListener(event: "drain", listener: () => void): this;
961
- addListener(event: "error", listener: (err: Error) => void): this;
962
- addListener(event: "finish", listener: () => void): this;
963
- addListener(event: "pipe", listener: (src: Readable) => void): this;
964
- addListener(event: "unpipe", listener: (src: Readable) => void): this;
965
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
966
- emit(event: "close"): boolean;
967
- emit(event: "drain"): boolean;
968
- emit(event: "error", err: Error): boolean;
969
- emit(event: "finish"): boolean;
970
- emit(event: "pipe", src: Readable): boolean;
971
- emit(event: "unpipe", src: Readable): boolean;
972
- emit(event: string | symbol, ...args: any[]): boolean;
973
- on(event: "close", listener: () => void): this;
974
- on(event: "drain", listener: () => void): this;
975
- on(event: "error", listener: (err: Error) => void): this;
976
- on(event: "finish", listener: () => void): this;
977
- on(event: "pipe", listener: (src: Readable) => void): this;
978
- on(event: "unpipe", listener: (src: Readable) => void): this;
979
- on(event: string | symbol, listener: (...args: any[]) => void): this;
980
- once(event: "close", listener: () => void): this;
981
- once(event: "drain", listener: () => void): this;
982
- once(event: "error", listener: (err: Error) => void): this;
983
- once(event: "finish", listener: () => void): this;
984
- once(event: "pipe", listener: (src: Readable) => void): this;
985
- once(event: "unpipe", listener: (src: Readable) => void): this;
986
- once(event: string | symbol, listener: (...args: any[]) => void): this;
987
- prependListener(event: "close", listener: () => void): this;
988
- prependListener(event: "drain", listener: () => void): this;
989
- prependListener(event: "error", listener: (err: Error) => void): this;
990
- prependListener(event: "finish", listener: () => void): this;
991
- prependListener(event: "pipe", listener: (src: Readable) => void): this;
992
- prependListener(event: "unpipe", listener: (src: Readable) => void): this;
993
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
994
- prependOnceListener(event: "close", listener: () => void): this;
995
- prependOnceListener(event: "drain", listener: () => void): this;
996
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
997
- prependOnceListener(event: "finish", listener: () => void): this;
998
- prependOnceListener(event: "pipe", listener: (src: Readable) => void): this;
999
- prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this;
1000
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
1001
- removeListener(event: "close", listener: () => void): this;
1002
- removeListener(event: "drain", listener: () => void): this;
1003
- removeListener(event: "error", listener: (err: Error) => void): this;
1004
- removeListener(event: "finish", listener: () => void): this;
1005
- removeListener(event: "pipe", listener: (src: Readable) => void): this;
1006
- removeListener(event: "unpipe", listener: (src: Readable) => void): this;
1007
- removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
1008
- }
1009
- interface DuplexOptions extends ReadableOptions, WritableOptions {
1010
- allowHalfOpen?: boolean | undefined;
1011
- readableObjectMode?: boolean | undefined;
1012
- writableObjectMode?: boolean | undefined;
1013
- readableHighWaterMark?: number | undefined;
1014
- writableHighWaterMark?: number | undefined;
1015
- writableCorked?: number | undefined;
1016
- construct?(this: Duplex, callback: (error?: Error | null) => void): void;
1017
- read?(this: Duplex, size: number): void;
1018
- write?(this: Duplex, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
1019
- writev?(
1020
- this: Duplex,
1021
- chunks: Array<{
1022
- chunk: any;
1023
- encoding: BufferEncoding;
1024
- }>,
1025
- callback: (error?: Error | null) => void,
1026
- ): void;
1027
- final?(this: Duplex, callback: (error?: Error | null) => void): void;
1028
- destroy?(this: Duplex, error: Error | null, callback: (error?: Error | null) => void): void;
1029
- }
1030
- /**
1031
- * Duplex streams are streams that implement both the `Readable` and `Writable` interfaces.
1032
- *
1033
- * Examples of `Duplex` streams include:
1034
- *
1035
- * * `TCP sockets`
1036
- * * `zlib streams`
1037
- * * `crypto streams`
1038
- * @since v0.9.4
1039
- */
1040
- class Duplex extends Readable implements Writable {
1041
- readonly writable: boolean;
1042
- readonly writableEnded: boolean;
1043
- readonly writableFinished: boolean;
1044
- readonly writableHighWaterMark: number;
1045
- readonly writableLength: number;
1046
- readonly writableObjectMode: boolean;
1047
- readonly writableCorked: number;
1048
- readonly writableNeedDrain: boolean;
1049
- readonly closed: boolean;
1050
- readonly errored: Error | null;
1051
- /**
1052
- * If `false` then the stream will automatically end the writable side when the
1053
- * readable side ends. Set initially by the `allowHalfOpen` constructor option,
1054
- * which defaults to `false`.
1055
- *
1056
- * This can be changed manually to change the half-open behavior of an existing`Duplex` stream instance, but must be changed before the `'end'` event is
1057
- * emitted.
1058
- * @since v0.9.4
1059
- */
1060
- allowHalfOpen: boolean;
1061
- constructor(opts?: DuplexOptions);
1062
- /**
1063
- * A utility method for creating duplex streams.
1064
- *
1065
- * - `Stream` converts writable stream into writable `Duplex` and readable stream
1066
- * to `Duplex`.
1067
- * - `Blob` converts into readable `Duplex`.
1068
- * - `string` converts into readable `Duplex`.
1069
- * - `ArrayBuffer` converts into readable `Duplex`.
1070
- * - `AsyncIterable` converts into a readable `Duplex`. Cannot yield `null`.
1071
- * - `AsyncGeneratorFunction` converts into a readable/writable transform
1072
- * `Duplex`. Must take a source `AsyncIterable` as first parameter. Cannot yield
1073
- * `null`.
1074
- * - `AsyncFunction` converts into a writable `Duplex`. Must return
1075
- * either `null` or `undefined`
1076
- * - `Object ({ writable, readable })` converts `readable` and
1077
- * `writable` into `Stream` and then combines them into `Duplex` where the
1078
- * `Duplex` will write to the `writable` and read from the `readable`.
1079
- * - `Promise` converts into readable `Duplex`. Value `null` is ignored.
1080
- *
1081
- * @since v16.8.0
1082
- */
1083
- static from(
1084
- src:
1085
- | Stream
1086
- | NodeBlob
1087
- | ArrayBuffer
1088
- | string
1089
- | Iterable<any>
1090
- | AsyncIterable<any>
1091
- | AsyncGeneratorFunction
1092
- | Promise<any>
1093
- | Object,
1094
- ): Duplex;
1095
- _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
1096
- _writev?(
1097
- chunks: Array<{
1098
- chunk: any;
1099
- encoding: BufferEncoding;
1100
- }>,
1101
- callback: (error?: Error | null) => void,
1102
- ): void;
1103
- _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
1104
- _final(callback: (error?: Error | null) => void): void;
1105
- write(chunk: any, encoding?: BufferEncoding, cb?: (error: Error | null | undefined) => void): boolean;
1106
- write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
1107
- setDefaultEncoding(encoding: BufferEncoding): this;
1108
- end(cb?: () => void): this;
1109
- end(chunk: any, cb?: () => void): this;
1110
- end(chunk: any, encoding?: BufferEncoding, cb?: () => void): this;
1111
- cork(): void;
1112
- uncork(): void;
1113
- /**
1114
- * Event emitter
1115
- * The defined events on documents including:
1116
- * 1. close
1117
- * 2. data
1118
- * 3. drain
1119
- * 4. end
1120
- * 5. error
1121
- * 6. finish
1122
- * 7. pause
1123
- * 8. pipe
1124
- * 9. readable
1125
- * 10. resume
1126
- * 11. unpipe
1127
- */
1128
- addListener(event: "close", listener: () => void): this;
1129
- addListener(event: "data", listener: (chunk: any) => void): this;
1130
- addListener(event: "drain", listener: () => void): this;
1131
- addListener(event: "end", listener: () => void): this;
1132
- addListener(event: "error", listener: (err: Error) => void): this;
1133
- addListener(event: "finish", listener: () => void): this;
1134
- addListener(event: "pause", listener: () => void): this;
1135
- addListener(event: "pipe", listener: (src: Readable) => void): this;
1136
- addListener(event: "readable", listener: () => void): this;
1137
- addListener(event: "resume", listener: () => void): this;
1138
- addListener(event: "unpipe", listener: (src: Readable) => void): this;
1139
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
1140
- emit(event: "close"): boolean;
1141
- emit(event: "data", chunk: any): boolean;
1142
- emit(event: "drain"): boolean;
1143
- emit(event: "end"): boolean;
1144
- emit(event: "error", err: Error): boolean;
1145
- emit(event: "finish"): boolean;
1146
- emit(event: "pause"): boolean;
1147
- emit(event: "pipe", src: Readable): boolean;
1148
- emit(event: "readable"): boolean;
1149
- emit(event: "resume"): boolean;
1150
- emit(event: "unpipe", src: Readable): boolean;
1151
- emit(event: string | symbol, ...args: any[]): boolean;
1152
- on(event: "close", listener: () => void): this;
1153
- on(event: "data", listener: (chunk: any) => void): this;
1154
- on(event: "drain", listener: () => void): this;
1155
- on(event: "end", listener: () => void): this;
1156
- on(event: "error", listener: (err: Error) => void): this;
1157
- on(event: "finish", listener: () => void): this;
1158
- on(event: "pause", listener: () => void): this;
1159
- on(event: "pipe", listener: (src: Readable) => void): this;
1160
- on(event: "readable", listener: () => void): this;
1161
- on(event: "resume", listener: () => void): this;
1162
- on(event: "unpipe", listener: (src: Readable) => void): this;
1163
- on(event: string | symbol, listener: (...args: any[]) => void): this;
1164
- once(event: "close", listener: () => void): this;
1165
- once(event: "data", listener: (chunk: any) => void): this;
1166
- once(event: "drain", listener: () => void): this;
1167
- once(event: "end", listener: () => void): this;
1168
- once(event: "error", listener: (err: Error) => void): this;
1169
- once(event: "finish", listener: () => void): this;
1170
- once(event: "pause", listener: () => void): this;
1171
- once(event: "pipe", listener: (src: Readable) => void): this;
1172
- once(event: "readable", listener: () => void): this;
1173
- once(event: "resume", listener: () => void): this;
1174
- once(event: "unpipe", listener: (src: Readable) => void): this;
1175
- once(event: string | symbol, listener: (...args: any[]) => void): this;
1176
- prependListener(event: "close", listener: () => void): this;
1177
- prependListener(event: "data", listener: (chunk: any) => void): this;
1178
- prependListener(event: "drain", listener: () => void): this;
1179
- prependListener(event: "end", listener: () => void): this;
1180
- prependListener(event: "error", listener: (err: Error) => void): this;
1181
- prependListener(event: "finish", listener: () => void): this;
1182
- prependListener(event: "pause", listener: () => void): this;
1183
- prependListener(event: "pipe", listener: (src: Readable) => void): this;
1184
- prependListener(event: "readable", listener: () => void): this;
1185
- prependListener(event: "resume", listener: () => void): this;
1186
- prependListener(event: "unpipe", listener: (src: Readable) => void): this;
1187
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
1188
- prependOnceListener(event: "close", listener: () => void): this;
1189
- prependOnceListener(event: "data", listener: (chunk: any) => void): this;
1190
- prependOnceListener(event: "drain", listener: () => void): this;
1191
- prependOnceListener(event: "end", listener: () => void): this;
1192
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
1193
- prependOnceListener(event: "finish", listener: () => void): this;
1194
- prependOnceListener(event: "pause", listener: () => void): this;
1195
- prependOnceListener(event: "pipe", listener: (src: Readable) => void): this;
1196
- prependOnceListener(event: "readable", listener: () => void): this;
1197
- prependOnceListener(event: "resume", listener: () => void): this;
1198
- prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this;
1199
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
1200
- removeListener(event: "close", listener: () => void): this;
1201
- removeListener(event: "data", listener: (chunk: any) => void): this;
1202
- removeListener(event: "drain", listener: () => void): this;
1203
- removeListener(event: "end", listener: () => void): this;
1204
- removeListener(event: "error", listener: (err: Error) => void): this;
1205
- removeListener(event: "finish", listener: () => void): this;
1206
- removeListener(event: "pause", listener: () => void): this;
1207
- removeListener(event: "pipe", listener: (src: Readable) => void): this;
1208
- removeListener(event: "readable", listener: () => void): this;
1209
- removeListener(event: "resume", listener: () => void): this;
1210
- removeListener(event: "unpipe", listener: (src: Readable) => void): this;
1211
- removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
1212
- }
1213
- type TransformCallback = (error?: Error | null, data?: any) => void;
1214
- interface TransformOptions extends DuplexOptions {
1215
- construct?(this: Transform, callback: (error?: Error | null) => void): void;
1216
- read?(this: Transform, size: number): void;
1217
- write?(
1218
- this: Transform,
1219
- chunk: any,
1220
- encoding: BufferEncoding,
1221
- callback: (error?: Error | null) => void,
1222
- ): void;
1223
- writev?(
1224
- this: Transform,
1225
- chunks: Array<{
1226
- chunk: any;
1227
- encoding: BufferEncoding;
1228
- }>,
1229
- callback: (error?: Error | null) => void,
1230
- ): void;
1231
- final?(this: Transform, callback: (error?: Error | null) => void): void;
1232
- destroy?(this: Transform, error: Error | null, callback: (error?: Error | null) => void): void;
1233
- transform?(this: Transform, chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
1234
- flush?(this: Transform, callback: TransformCallback): void;
1235
- }
1236
- /**
1237
- * Transform streams are `Duplex` streams where the output is in some way
1238
- * related to the input. Like all `Duplex` streams, `Transform` streams
1239
- * implement both the `Readable` and `Writable` interfaces.
1240
- *
1241
- * Examples of `Transform` streams include:
1242
- *
1243
- * * `zlib streams`
1244
- * * `crypto streams`
1245
- * @since v0.9.4
1246
- */
1247
- class Transform extends Duplex {
1248
- constructor(opts?: TransformOptions);
1249
- _transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
1250
- _flush(callback: TransformCallback): void;
1251
- }
1252
- /**
1253
- * 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
1254
- * 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.
1255
- */
1256
- class PassThrough extends Transform {}
1257
- /**
1258
- * Attaches an AbortSignal to a readable or writeable stream. This lets code
1259
- * control stream destruction using an `AbortController`.
1260
- *
1261
- * Calling `abort` on the `AbortController` corresponding to the passed`AbortSignal` will behave the same way as calling `.destroy(new AbortError())`on the stream.
1262
- *
1263
- * ```js
1264
- * const fs = require('fs');
1265
- *
1266
- * const controller = new AbortController();
1267
- * const read = addAbortSignal(
1268
- * controller.signal,
1269
- * fs.createReadStream(('object.json'))
1270
- * );
1271
- * // Later, abort the operation closing the stream
1272
- * controller.abort();
1273
- * ```
1274
- *
1275
- * Or using an `AbortSignal` with a readable stream as an async iterable:
1276
- *
1277
- * ```js
1278
- * const controller = new AbortController();
1279
- * setTimeout(() => controller.abort(), 10_000); // set a timeout
1280
- * const stream = addAbortSignal(
1281
- * controller.signal,
1282
- * fs.createReadStream(('object.json'))
1283
- * );
1284
- * (async () => {
1285
- * try {
1286
- * for await (const chunk of stream) {
1287
- * await process(chunk);
1288
- * }
1289
- * } catch (e) {
1290
- * if (e.name === 'AbortError') {
1291
- * // The operation was cancelled
1292
- * } else {
1293
- * throw e;
1294
- * }
1295
- * }
1296
- * })();
1297
- * ```
1298
- * @since v15.4.0
1299
- * @param signal A signal representing possible cancellation
1300
- * @param stream a stream to attach a signal to
1301
- */
1302
- function addAbortSignal<T extends Stream>(signal: AbortSignal, stream: T): T;
1303
- /**
1304
- * Returns the default highWaterMark used by streams.
1305
- * Defaults to `16384` (16 KiB), or `16` for `objectMode`.
1306
- * @since v18.17.0
1307
- * @param objectMode
1308
- */
1309
- function getDefaultHighWaterMark(objectMode: boolean): number;
1310
- /**
1311
- * Sets the default highWaterMark used by streams.
1312
- * @since v18.17.0
1313
- * @param objectMode
1314
- * @param value highWaterMark value
1315
- */
1316
- function setDefaultHighWaterMark(objectMode: boolean, value: number): void;
1317
- interface FinishedOptions extends Abortable {
1318
- error?: boolean | undefined;
1319
- readable?: boolean | undefined;
1320
- writable?: boolean | undefined;
1321
- }
1322
- /**
1323
- * A function to get notified when a stream is no longer readable, writable
1324
- * or has experienced an error or a premature close event.
1325
- *
1326
- * ```js
1327
- * const { finished } = require('stream');
1328
- *
1329
- * const rs = fs.createReadStream('archive.tar');
1330
- *
1331
- * finished(rs, (err) => {
1332
- * if (err) {
1333
- * console.error('Stream failed.', err);
1334
- * } else {
1335
- * console.log('Stream is done reading.');
1336
- * }
1337
- * });
1338
- *
1339
- * rs.resume(); // Drain the stream.
1340
- * ```
1341
- *
1342
- * Especially useful in error handling scenarios where a stream is destroyed
1343
- * prematurely (like an aborted HTTP request), and will not emit `'end'`or `'finish'`.
1344
- *
1345
- * The `finished` API provides promise version:
1346
- *
1347
- * ```js
1348
- * const { finished } = require('stream/promises');
1349
- *
1350
- * const rs = fs.createReadStream('archive.tar');
1351
- *
1352
- * async function run() {
1353
- * await finished(rs);
1354
- * console.log('Stream is done reading.');
1355
- * }
1356
- *
1357
- * run().catch(console.error);
1358
- * rs.resume(); // Drain the stream.
1359
- * ```
1360
- *
1361
- * `stream.finished()` leaves dangling event listeners (in particular`'error'`, `'end'`, `'finish'` and `'close'`) after `callback` has been
1362
- * invoked. The reason for this is so that unexpected `'error'` events (due to
1363
- * incorrect stream implementations) do not cause unexpected crashes.
1364
- * If this is unwanted behavior then the returned cleanup function needs to be
1365
- * invoked in the callback:
1366
- *
1367
- * ```js
1368
- * const cleanup = finished(rs, (err) => {
1369
- * cleanup();
1370
- * // ...
1371
- * });
1372
- * ```
1373
- * @since v10.0.0
1374
- * @param stream A readable and/or writable stream.
1375
- * @param callback A callback function that takes an optional error argument.
1376
- * @return A cleanup function which removes all registered listeners.
1377
- */
1378
- function finished(
1379
- stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream,
1380
- options: FinishedOptions,
1381
- callback: (err?: NodeJS.ErrnoException | null) => void,
1382
- ): () => void;
1383
- function finished(
1384
- stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream,
1385
- callback: (err?: NodeJS.ErrnoException | null) => void,
1386
- ): () => void;
1387
- namespace finished {
1388
- function __promisify__(
1389
- stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream,
1390
- options?: FinishedOptions,
1391
- ): Promise<void>;
1392
- }
1393
- type PipelineSourceFunction<T> = () => Iterable<T> | AsyncIterable<T>;
1394
- type PipelineSource<T> = Iterable<T> | AsyncIterable<T> | NodeJS.ReadableStream | PipelineSourceFunction<T>;
1395
- type PipelineTransform<S extends PipelineTransformSource<any>, U> =
1396
- | NodeJS.ReadWriteStream
1397
- | ((
1398
- source: S extends (...args: any[]) => Iterable<infer ST> | AsyncIterable<infer ST> ? AsyncIterable<ST>
1399
- : S,
1400
- ) => AsyncIterable<U>);
1401
- type PipelineTransformSource<T> = PipelineSource<T> | PipelineTransform<any, T>;
1402
- type PipelineDestinationIterableFunction<T> = (source: AsyncIterable<T>) => AsyncIterable<any>;
1403
- type PipelineDestinationPromiseFunction<T, P> = (source: AsyncIterable<T>) => Promise<P>;
1404
- type PipelineDestination<S extends PipelineTransformSource<any>, P> = S extends
1405
- PipelineTransformSource<infer ST> ?
1406
- | NodeJS.WritableStream
1407
- | PipelineDestinationIterableFunction<ST>
1408
- | PipelineDestinationPromiseFunction<ST, P>
1409
- : never;
1410
- type PipelineCallback<S extends PipelineDestination<any, any>> = S extends
1411
- PipelineDestinationPromiseFunction<any, infer P> ? (err: NodeJS.ErrnoException | null, value: P) => void
1412
- : (err: NodeJS.ErrnoException | null) => void;
1413
- type PipelinePromise<S extends PipelineDestination<any, any>> = S extends
1414
- PipelineDestinationPromiseFunction<any, infer P> ? Promise<P> : Promise<void>;
1415
- interface PipelineOptions {
1416
- signal?: AbortSignal | undefined;
1417
- end?: boolean | undefined;
1418
- }
1419
- /**
1420
- * A module method to pipe between streams and generators forwarding errors and
1421
- * properly cleaning up and provide a callback when the pipeline is complete.
1422
- *
1423
- * ```js
1424
- * const { pipeline } = require('stream');
1425
- * const fs = require('fs');
1426
- * const zlib = require('zlib');
1427
- *
1428
- * // Use the pipeline API to easily pipe a series of streams
1429
- * // together and get notified when the pipeline is fully done.
1430
- *
1431
- * // A pipeline to gzip a potentially huge tar file efficiently:
1432
- *
1433
- * pipeline(
1434
- * fs.createReadStream('archive.tar'),
1435
- * zlib.createGzip(),
1436
- * fs.createWriteStream('archive.tar.gz'),
1437
- * (err) => {
1438
- * if (err) {
1439
- * console.error('Pipeline failed.', err);
1440
- * } else {
1441
- * console.log('Pipeline succeeded.');
1442
- * }
1443
- * }
1444
- * );
1445
- * ```
1446
- *
1447
- * The `pipeline` API provides a promise version, which can also
1448
- * receive an options argument as the last parameter with a`signal` `AbortSignal` property. When the signal is aborted,`destroy` will be called on the underlying pipeline, with
1449
- * an`AbortError`.
1450
- *
1451
- * ```js
1452
- * const { pipeline } = require('stream/promises');
1453
- *
1454
- * async function run() {
1455
- * await pipeline(
1456
- * fs.createReadStream('archive.tar'),
1457
- * zlib.createGzip(),
1458
- * fs.createWriteStream('archive.tar.gz')
1459
- * );
1460
- * console.log('Pipeline succeeded.');
1461
- * }
1462
- *
1463
- * run().catch(console.error);
1464
- * ```
1465
- *
1466
- * To use an `AbortSignal`, pass it inside an options object,
1467
- * as the last argument:
1468
- *
1469
- * ```js
1470
- * const { pipeline } = require('stream/promises');
1471
- *
1472
- * async function run() {
1473
- * const ac = new AbortController();
1474
- * const signal = ac.signal;
1475
- *
1476
- * setTimeout(() => ac.abort(), 1);
1477
- * await pipeline(
1478
- * fs.createReadStream('archive.tar'),
1479
- * zlib.createGzip(),
1480
- * fs.createWriteStream('archive.tar.gz'),
1481
- * { signal },
1482
- * );
1483
- * }
1484
- *
1485
- * run().catch(console.error); // AbortError
1486
- * ```
1487
- *
1488
- * The `pipeline` API also supports async generators:
1489
- *
1490
- * ```js
1491
- * const { pipeline } = require('stream/promises');
1492
- * const fs = require('fs');
1493
- *
1494
- * async function run() {
1495
- * await pipeline(
1496
- * fs.createReadStream('lowercase.txt'),
1497
- * async function* (source, { signal }) {
1498
- * source.setEncoding('utf8'); // Work with strings rather than `Buffer`s.
1499
- * for await (const chunk of source) {
1500
- * yield await processChunk(chunk, { signal });
1501
- * }
1502
- * },
1503
- * fs.createWriteStream('uppercase.txt')
1504
- * );
1505
- * console.log('Pipeline succeeded.');
1506
- * }
1507
- *
1508
- * run().catch(console.error);
1509
- * ```
1510
- *
1511
- * Remember to handle the `signal` argument passed into the async generator.
1512
- * Especially in the case where the async generator is the source for the
1513
- * pipeline (i.e. first argument) or the pipeline will never complete.
1514
- *
1515
- * ```js
1516
- * const { pipeline } = require('stream/promises');
1517
- * const fs = require('fs');
1518
- *
1519
- * async function run() {
1520
- * await pipeline(
1521
- * async function* ({ signal }) {
1522
- * await someLongRunningfn({ signal });
1523
- * yield 'asd';
1524
- * },
1525
- * fs.createWriteStream('uppercase.txt')
1526
- * );
1527
- * console.log('Pipeline succeeded.');
1528
- * }
1529
- *
1530
- * run().catch(console.error);
1531
- * ```
1532
- *
1533
- * `stream.pipeline()` will call `stream.destroy(err)` on all streams except:
1534
- *
1535
- * * `Readable` streams which have emitted `'end'` or `'close'`.
1536
- * * `Writable` streams which have emitted `'finish'` or `'close'`.
1537
- *
1538
- * `stream.pipeline()` leaves dangling event listeners on the streams
1539
- * after the `callback` has been invoked. In the case of reuse of streams after
1540
- * failure, this can cause event listener leaks and swallowed errors. If the last
1541
- * stream is readable, dangling event listeners will be removed so that the last
1542
- * stream can be consumed later.
1543
- *
1544
- * `stream.pipeline()` closes all the streams when an error is raised.
1545
- * The `IncomingRequest` usage with `pipeline` could lead to an unexpected behavior
1546
- * once it would destroy the socket without sending the expected response.
1547
- * See the example below:
1548
- *
1549
- * ```js
1550
- * const fs = require('fs');
1551
- * const http = require('http');
1552
- * const { pipeline } = require('stream');
1553
- *
1554
- * const server = http.createServer((req, res) => {
1555
- * const fileStream = fs.createReadStream('./fileNotExist.txt');
1556
- * pipeline(fileStream, res, (err) => {
1557
- * if (err) {
1558
- * console.log(err); // No such file
1559
- * // this message can't be sent once `pipeline` already destroyed the socket
1560
- * return res.end('error!!!');
1561
- * }
1562
- * });
1563
- * });
1564
- * ```
1565
- * @since v10.0.0
1566
- * @param callback Called when the pipeline is fully done.
1567
- */
1568
- function pipeline<A extends PipelineSource<any>, B extends PipelineDestination<A, any>>(
1569
- source: A,
1570
- destination: B,
1571
- callback?: PipelineCallback<B>,
1572
- ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1573
- function pipeline<
1574
- A extends PipelineSource<any>,
1575
- T1 extends PipelineTransform<A, any>,
1576
- B extends PipelineDestination<T1, any>,
1577
- >(
1578
- source: A,
1579
- transform1: T1,
1580
- destination: B,
1581
- callback?: PipelineCallback<B>,
1582
- ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1583
- function pipeline<
1584
- A extends PipelineSource<any>,
1585
- T1 extends PipelineTransform<A, any>,
1586
- T2 extends PipelineTransform<T1, any>,
1587
- B extends PipelineDestination<T2, any>,
1588
- >(
1589
- source: A,
1590
- transform1: T1,
1591
- transform2: T2,
1592
- destination: B,
1593
- callback?: PipelineCallback<B>,
1594
- ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1595
- function pipeline<
1596
- A extends PipelineSource<any>,
1597
- T1 extends PipelineTransform<A, any>,
1598
- T2 extends PipelineTransform<T1, any>,
1599
- T3 extends PipelineTransform<T2, any>,
1600
- B extends PipelineDestination<T3, any>,
1601
- >(
1602
- source: A,
1603
- transform1: T1,
1604
- transform2: T2,
1605
- transform3: T3,
1606
- destination: B,
1607
- callback?: PipelineCallback<B>,
1608
- ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1609
- function pipeline<
1610
- A extends PipelineSource<any>,
1611
- T1 extends PipelineTransform<A, any>,
1612
- T2 extends PipelineTransform<T1, any>,
1613
- T3 extends PipelineTransform<T2, any>,
1614
- T4 extends PipelineTransform<T3, any>,
1615
- B extends PipelineDestination<T4, any>,
1616
- >(
1617
- source: A,
1618
- transform1: T1,
1619
- transform2: T2,
1620
- transform3: T3,
1621
- transform4: T4,
1622
- destination: B,
1623
- callback?: PipelineCallback<B>,
1624
- ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1625
- function pipeline(
1626
- streams: ReadonlyArray<NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream>,
1627
- callback?: (err: NodeJS.ErrnoException | null) => void,
1628
- ): NodeJS.WritableStream;
1629
- function pipeline(
1630
- stream1: NodeJS.ReadableStream,
1631
- stream2: NodeJS.ReadWriteStream | NodeJS.WritableStream,
1632
- ...streams: Array<
1633
- NodeJS.ReadWriteStream | NodeJS.WritableStream | ((err: NodeJS.ErrnoException | null) => void)
1634
- >
1635
- ): NodeJS.WritableStream;
1636
- namespace pipeline {
1637
- function __promisify__<A extends PipelineSource<any>, B extends PipelineDestination<A, any>>(
1638
- source: A,
1639
- destination: B,
1640
- options?: PipelineOptions,
1641
- ): PipelinePromise<B>;
1642
- function __promisify__<
1643
- A extends PipelineSource<any>,
1644
- T1 extends PipelineTransform<A, any>,
1645
- B extends PipelineDestination<T1, any>,
1646
- >(
1647
- source: A,
1648
- transform1: T1,
1649
- destination: B,
1650
- options?: PipelineOptions,
1651
- ): PipelinePromise<B>;
1652
- function __promisify__<
1653
- A extends PipelineSource<any>,
1654
- T1 extends PipelineTransform<A, any>,
1655
- T2 extends PipelineTransform<T1, any>,
1656
- B extends PipelineDestination<T2, any>,
1657
- >(
1658
- source: A,
1659
- transform1: T1,
1660
- transform2: T2,
1661
- destination: B,
1662
- options?: PipelineOptions,
1663
- ): PipelinePromise<B>;
1664
- function __promisify__<
1665
- A extends PipelineSource<any>,
1666
- T1 extends PipelineTransform<A, any>,
1667
- T2 extends PipelineTransform<T1, any>,
1668
- T3 extends PipelineTransform<T2, any>,
1669
- B extends PipelineDestination<T3, any>,
1670
- >(
1671
- source: A,
1672
- transform1: T1,
1673
- transform2: T2,
1674
- transform3: T3,
1675
- destination: B,
1676
- options?: PipelineOptions,
1677
- ): PipelinePromise<B>;
1678
- function __promisify__<
1679
- A extends PipelineSource<any>,
1680
- T1 extends PipelineTransform<A, any>,
1681
- T2 extends PipelineTransform<T1, any>,
1682
- T3 extends PipelineTransform<T2, any>,
1683
- T4 extends PipelineTransform<T3, any>,
1684
- B extends PipelineDestination<T4, any>,
1685
- >(
1686
- source: A,
1687
- transform1: T1,
1688
- transform2: T2,
1689
- transform3: T3,
1690
- transform4: T4,
1691
- destination: B,
1692
- options?: PipelineOptions,
1693
- ): PipelinePromise<B>;
1694
- function __promisify__(
1695
- streams: ReadonlyArray<NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream>,
1696
- options?: PipelineOptions,
1697
- ): Promise<void>;
1698
- function __promisify__(
1699
- stream1: NodeJS.ReadableStream,
1700
- stream2: NodeJS.ReadWriteStream | NodeJS.WritableStream,
1701
- ...streams: Array<NodeJS.ReadWriteStream | NodeJS.WritableStream | PipelineOptions>
1702
- ): Promise<void>;
1703
- }
1704
- interface Pipe {
1705
- close(): void;
1706
- hasRef(): boolean;
1707
- ref(): void;
1708
- unref(): void;
1709
- }
1710
-
1711
- /**
1712
- * Returns whether the stream has encountered an error.
1713
- * @since v17.3.0
1714
- */
1715
- function isErrored(stream: Readable | Writable | NodeJS.ReadableStream | NodeJS.WritableStream): boolean;
1716
-
1717
- /**
1718
- * Returns whether the stream is readable.
1719
- * @since v17.4.0
1720
- */
1721
- function isReadable(stream: Readable | NodeJS.ReadableStream): boolean;
1722
-
1723
- const promises: typeof streamPromises;
1724
- const consumers: typeof streamConsumers;
1725
- }
1726
- export = internal;
1727
- }
1728
- declare module "node:stream" {
1729
- import stream = require("stream");
1730
- export = stream;
1731
- }