@types/node 18.7.17 → 18.7.19

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