@types/node 20.12.11 → 20.12.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
node/stream.d.ts CHANGED
@@ -2,9 +2,10 @@
2
2
  * A stream is an abstract interface for working with streaming data in Node.js.
3
3
  * The `node:stream` module provides an API for implementing the stream interface.
4
4
  *
5
- * There are many stream objects provided by Node.js. For instance, a `request to an HTTP server` and `process.stdout` are both stream instances.
5
+ * There are many stream objects provided by Node.js. For instance, a [request to an HTTP server](https://nodejs.org/docs/latest-v20.x/api/http.html#class-httpincomingmessage)
6
+ * and [`process.stdout`](https://nodejs.org/docs/latest-v20.x/api/process.html#processstdout) are both stream instances.
6
7
  *
7
- * Streams can be readable, writable, or both. All streams are instances of `EventEmitter`.
8
+ * Streams can be readable, writable, or both. All streams are instances of [`EventEmitter`](https://nodejs.org/docs/latest-v20.x/api/events.html#class-eventemitter).
8
9
  *
9
10
  * To access the `node:stream` module:
10
11
  *
@@ -14,7 +15,7 @@
14
15
  *
15
16
  * The `node:stream` module is useful for creating new types of stream instances.
16
17
  * It is usually not necessary to use the `node:stream` module to consume streams.
17
- * @see [source](https://github.com/nodejs/node/blob/v20.12.2/lib/stream.js)
18
+ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/stream.js)
18
19
  */
19
20
  declare module "stream" {
20
21
  import { Abortable, EventEmitter } from "node:events";
@@ -41,16 +42,20 @@ declare module "stream" {
41
42
  import Readable = internal.Readable;
42
43
  import ReadableOptions = internal.ReadableOptions;
43
44
  interface ArrayOptions {
44
- /** the maximum concurrent invocations of `fn` to call on the stream at once.
45
+ /**
46
+ * The maximum concurrent invocations of `fn` to call on the stream at once.
45
47
  * @default 1
46
48
  */
47
49
  concurrency?: number;
48
- /** allows destroying the stream if the signal is aborted. */
50
+ /** Allows destroying the stream if the signal is aborted. */
49
51
  signal?: AbortSignal;
50
52
  }
51
53
  class ReadableBase extends Stream implements NodeJS.ReadableStream {
52
54
  /**
53
55
  * A utility method for creating Readable Streams out of iterators.
56
+ * @since v12.3.0, v10.17.0
57
+ * @param iterable Object implementing the `Symbol.asyncIterator` or `Symbol.iterator` iterable protocol. Emits an 'error' event if a null value is passed.
58
+ * @param options Options provided to `new stream.Readable([options])`. By default, `Readable.from()` will set `options.objectMode` to `true`, unless this is explicitly opted out by setting `options.objectMode` to `false`.
54
59
  */
55
60
  static from(iterable: Iterable<any> | AsyncIterable<any>, options?: ReadableOptions): Readable;
56
61
  /**
@@ -65,7 +70,7 @@ declare module "stream" {
65
70
  */
66
71
  readonly readableAborted: boolean;
67
72
  /**
68
- * Is `true` if it is safe to call `readable.read()`, which means
73
+ * Is `true` if it is safe to call {@link read}, which means
69
74
  * the stream has not been destroyed or emitted `'error'` or `'end'`.
70
75
  * @since v11.4.0
71
76
  */
@@ -77,18 +82,18 @@ declare module "stream" {
77
82
  */
78
83
  readonly readableDidRead: boolean;
79
84
  /**
80
- * Getter for the property `encoding` of a given `Readable` stream. The `encoding` property can be set using the `readable.setEncoding()` method.
85
+ * Getter for the property `encoding` of a given `Readable` stream. The `encoding` property can be set using the {@link setEncoding} method.
81
86
  * @since v12.7.0
82
87
  */
83
88
  readonly readableEncoding: BufferEncoding | null;
84
89
  /**
85
- * Becomes `true` when `'end'` event is emitted.
90
+ * Becomes `true` when [`'end'`](https://nodejs.org/docs/latest-v20.x/api/stream.html#event-end) event is emitted.
86
91
  * @since v12.9.0
87
92
  */
88
93
  readonly readableEnded: boolean;
89
94
  /**
90
95
  * This property reflects the current state of a `Readable` stream as described
91
- * in the `Three states` section.
96
+ * in the [Three states](https://nodejs.org/docs/latest-v20.x/api/stream.html#three-states) section.
92
97
  * @since v9.4.0
93
98
  */
94
99
  readonly readableFlowing: boolean | null;
@@ -134,9 +139,10 @@ declare module "stream" {
134
139
  * specified using the `readable.setEncoding()` method or the stream is operating
135
140
  * in object mode.
136
141
  *
137
- * 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
138
- * case all of the data remaining in the internal
139
- * buffer will be returned.
142
+ * The optional `size` argument specifies a specific number of bytes to read. If
143
+ * `size` bytes are not available to be read, `null` will be returned _unless_ the
144
+ * stream has ended, in which case all of the data remaining in the internal buffer
145
+ * will be returned.
140
146
  *
141
147
  * If the `size` argument is not specified, all of the data contained in the
142
148
  * internal buffer will be returned.
@@ -193,7 +199,7 @@ declare module "stream" {
193
199
  * ```
194
200
  *
195
201
  * A `Readable` stream in object mode will always return a single item from
196
- * a call to `readable.read(size)`, regardless of the value of the`size` argument.
202
+ * a call to `readable.read(size)`, regardless of the value of the `size` argument.
197
203
  *
198
204
  * If the `readable.read()` method returns a chunk of data, a `'data'` event will
199
205
  * also be emitted.
@@ -208,9 +214,9 @@ declare module "stream" {
208
214
  * The `readable.setEncoding()` method sets the character encoding for
209
215
  * data read from the `Readable` stream.
210
216
  *
211
- * By default, no encoding is assigned and stream data will be returned as`Buffer` objects. Setting an encoding causes the stream data
217
+ * By default, no encoding is assigned and stream data will be returned as `Buffer` objects. Setting an encoding causes the stream data
212
218
  * to be returned as strings of the specified encoding rather than as `Buffer` objects. For instance, calling `readable.setEncoding('utf8')` will cause the
213
- * 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
219
+ * 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
214
220
  * string format.
215
221
  *
216
222
  * The `Readable` stream will properly handle multi-byte characters delivered
@@ -247,7 +253,7 @@ declare module "stream" {
247
253
  * });
248
254
  * ```
249
255
  *
250
- * The `readable.pause()` method has no effect if there is a `'readable'`event listener.
256
+ * The `readable.pause()` method has no effect if there is a `'readable'` event listener.
251
257
  * @since v0.9.4
252
258
  */
253
259
  pause(): this;
@@ -266,14 +272,14 @@ declare module "stream" {
266
272
  * });
267
273
  * ```
268
274
  *
269
- * The `readable.resume()` method has no effect if there is a `'readable'`event listener.
275
+ * The `readable.resume()` method has no effect if there is a `'readable'` event listener.
270
276
  * @since v0.9.4
271
277
  */
272
278
  resume(): this;
273
279
  /**
274
- * 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
275
- * typical cases, there will be no reason to
276
- * use this method directly.
280
+ * The `readable.isPaused()` method returns the current operating state of the `Readable`.
281
+ * This is used primarily by the mechanism that underlies the `readable.pipe()` method.
282
+ * In most typical cases, there will be no reason to use this method directly.
277
283
  *
278
284
  * ```js
279
285
  * const readable = new stream.Readable();
@@ -375,8 +381,8 @@ declare module "stream" {
375
381
  * however it is best to simply avoid calling `readable.unshift()` while in the
376
382
  * process of performing a read.
377
383
  * @since v0.9.11
378
- * @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
379
- * streams, `chunk` may be any JavaScript value.
384
+ * @param chunk Chunk of data to unshift onto the read queue. For streams not operating in object mode, `chunk` must
385
+ * be a {string}, {Buffer}, {TypedArray}, {DataView} or `null`. For object mode streams, `chunk` may be any JavaScript value.
380
386
  * @param encoding Encoding of string chunks. Must be a valid `Buffer` encoding, such as `'utf8'` or `'ascii'`.
381
387
  */
382
388
  unshift(chunk: any, encoding?: BufferEncoding): void;
@@ -384,7 +390,7 @@ declare module "stream" {
384
390
  * Prior to Node.js 0.10, streams did not implement the entire `node:stream` module API as it is currently defined. (See `Compatibility` for more
385
391
  * information.)
386
392
  *
387
- * 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`
393
+ * 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`
388
394
  * stream that uses
389
395
  * the old stream as its data source.
390
396
  *
@@ -567,8 +573,8 @@ declare module "stream" {
567
573
  ): Promise<T>;
568
574
  _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
569
575
  /**
570
- * Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'`event (unless `emitClose` is set to `false`). After this call, the readable
571
- * stream will release any internal resources and subsequent calls to `push()`will be ignored.
576
+ * Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'` event (unless `emitClose` is set to `false`). After this call, the readable
577
+ * stream will release any internal resources and subsequent calls to `push()` will be ignored.
572
578
  *
573
579
  * Once `destroy()` has been called any further calls will be a no-op and no
574
580
  * further errors except from `_destroy()` may be emitted as `'error'`.
@@ -733,7 +739,7 @@ declare module "stream" {
733
739
  * first argument. The `callback` is called asynchronously and before `'error'` is
734
740
  * emitted.
735
741
  *
736
- * The return value is `true` if the internal buffer is less than the`highWaterMark` configured when the stream was created after admitting `chunk`.
742
+ * The return value is `true` if the internal buffer is less than the `highWaterMark` configured when the stream was created after admitting `chunk`.
737
743
  * If `false` is returned, further attempts to write data to the stream should
738
744
  * stop until the `'drain'` event is emitted.
739
745
  *
@@ -776,8 +782,8 @@ declare module "stream" {
776
782
  *
777
783
  * A `Writable` stream in object mode will always ignore the `encoding` argument.
778
784
  * @since v0.9.4
779
- * @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
780
- * JavaScript value other than `null`.
785
+ * @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a {string}, {Buffer},
786
+ * {TypedArray} or {DataView}. For object mode streams, `chunk` may be any JavaScript value other than `null`.
781
787
  * @param [encoding='utf8'] The encoding, if `chunk` is a string.
782
788
  * @param callback Callback for when this chunk of data is flushed.
783
789
  * @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`.
@@ -807,8 +813,8 @@ declare module "stream" {
807
813
  * // Writing more now is not allowed!
808
814
  * ```
809
815
  * @since v0.9.4
810
- * @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
811
- * JavaScript value other than `null`.
816
+ * @param chunk Optional data to write. For streams not operating in object mode, `chunk` must be a {string}, {Buffer},
817
+ * {TypedArray} or {DataView}. For object mode streams, `chunk` may be any JavaScript value other than `null`.
812
818
  * @param encoding The encoding if `chunk` is a string
813
819
  * @param callback Callback for when the stream is finished.
814
820
  */
@@ -821,10 +827,10 @@ declare module "stream" {
821
827
  *
822
828
  * The primary intent of `writable.cork()` is to accommodate a situation in which
823
829
  * several small chunks are written to the stream in rapid succession. Instead of
824
- * immediately forwarding them to the underlying destination, `writable.cork()`buffers all the chunks until `writable.uncork()` is called, which will pass them
830
+ * immediately forwarding them to the underlying destination, `writable.cork()` buffers all the chunks until `writable.uncork()` is called, which will pass them
825
831
  * all to `writable._writev()`, if present. This prevents a head-of-line blocking
826
832
  * situation where data is being buffered while waiting for the first small chunk
827
- * to be processed. However, use of `writable.cork()` without implementing`writable._writev()` may have an adverse effect on throughput.
833
+ * to be processed. However, use of `writable.cork()` without implementing `writable._writev()` may have an adverse effect on throughput.
828
834
  *
829
835
  * See also: `writable.uncork()`, `writable._writev()`.
830
836
  * @since v0.11.2
@@ -834,7 +840,7 @@ declare module "stream" {
834
840
  * The `writable.uncork()` method flushes all data buffered since {@link cork} was called.
835
841
  *
836
842
  * When using `writable.cork()` and `writable.uncork()` to manage the buffering
837
- * 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
843
+ * 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
838
844
  * loop phase.
839
845
  *
840
846
  * ```js
@@ -865,10 +871,10 @@ declare module "stream" {
865
871
  */
866
872
  uncork(): void;
867
873
  /**
868
- * Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'`event (unless `emitClose` is set to `false`). After this call, the writable
874
+ * Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'` event (unless `emitClose` is set to `false`). After this call, the writable
869
875
  * stream has ended and subsequent calls to `write()` or `end()` will result in
870
876
  * an `ERR_STREAM_DESTROYED` error.
871
- * 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.
877
+ * 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.
872
878
  * Use `end()` instead of destroy if data should flush before close, or wait for
873
879
  * the `'drain'` event before destroying the stream.
874
880
  *
@@ -1063,8 +1069,8 @@ declare module "stream" {
1063
1069
  * readable side ends. Set initially by the `allowHalfOpen` constructor option,
1064
1070
  * which defaults to `true`.
1065
1071
  *
1066
- * 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
1067
- * emitted.
1072
+ * This can be changed manually to change the half-open behavior of an existing
1073
+ * `Duplex` stream instance, but must be changed before the `'end'` event is emitted.
1068
1074
  * @since v0.9.4
1069
1075
  */
1070
1076
  allowHalfOpen: boolean;
@@ -1285,7 +1291,7 @@ declare module "stream" {
1285
1291
  }
1286
1292
  /**
1287
1293
  * 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
1288
- * primarily for examples and testing, but there are some use cases where`stream.PassThrough` is useful as a building block for novel sorts of streams.
1294
+ * 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.
1289
1295
  */
1290
1296
  class PassThrough extends Transform {}
1291
1297
  /**
@@ -1294,8 +1300,8 @@ declare module "stream" {
1294
1300
  * Attaches an AbortSignal to a readable or writeable stream. This lets code
1295
1301
  * control stream destruction using an `AbortController`.
1296
1302
  *
1297
- * Calling `abort` on the `AbortController` corresponding to the passed`AbortSignal` will behave the same way as calling `.destroy(new AbortError())`on the stream, and `controller.error(new
1298
- * AbortError())` for webstreams.
1303
+ * Calling `abort` on the `AbortController` corresponding to the passed `AbortSignal` will behave the same way as calling `.destroy(new AbortError())` on the
1304
+ * stream, and `controller.error(new AbortError())` for webstreams.
1299
1305
  *
1300
1306
  * ```js
1301
1307
  * const fs = require('node:fs');
@@ -1365,20 +1371,18 @@ declare module "stream" {
1365
1371
  * ```
1366
1372
  * @since v15.4.0
1367
1373
  * @param signal A signal representing possible cancellation
1368
- * @param stream a stream to attach a signal to
1374
+ * @param stream A stream to attach a signal to.
1369
1375
  */
1370
1376
  function addAbortSignal<T extends Stream>(signal: AbortSignal, stream: T): T;
1371
1377
  /**
1372
1378
  * Returns the default highWaterMark used by streams.
1373
1379
  * Defaults to `16384` (16 KiB), or `16` for `objectMode`.
1374
1380
  * @since v19.9.0
1375
- * @param objectMode
1376
1381
  */
1377
1382
  function getDefaultHighWaterMark(objectMode: boolean): number;
1378
1383
  /**
1379
1384
  * Sets the default highWaterMark used by streams.
1380
1385
  * @since v19.9.0
1381
- * @param objectMode
1382
1386
  * @param value highWaterMark value
1383
1387
  */
1384
1388
  function setDefaultHighWaterMark(objectMode: boolean, value: number): void;
@@ -1411,11 +1415,11 @@ declare module "stream" {
1411
1415
  * ```
1412
1416
  *
1413
1417
  * Especially useful in error handling scenarios where a stream is destroyed
1414
- * prematurely (like an aborted HTTP request), and will not emit `'end'`or `'finish'`.
1418
+ * prematurely (like an aborted HTTP request), and will not emit `'end'` or `'finish'`.
1415
1419
  *
1416
- * The `finished` API provides `promise version`.
1420
+ * The `finished` API provides [`promise version`](https://nodejs.org/docs/latest-v20.x/api/stream.html#streamfinishedstream-options).
1417
1421
  *
1418
- * `stream.finished()` leaves dangling event listeners (in particular`'error'`, `'end'`, `'finish'` and `'close'`) after `callback` has been
1422
+ * `stream.finished()` leaves dangling event listeners (in particular `'error'`, `'end'`, `'finish'` and `'close'`) after `callback` has been
1419
1423
  * invoked. The reason for this is so that unexpected `'error'` events (due to
1420
1424
  * incorrect stream implementations) do not cause unexpected crashes.
1421
1425
  * If this is unwanted behavior then the returned cleanup function needs to be
@@ -1430,7 +1434,7 @@ declare module "stream" {
1430
1434
  * @since v10.0.0
1431
1435
  * @param stream A readable and/or writable stream.
1432
1436
  * @param callback A callback function that takes an optional error argument.
1433
- * @return A cleanup function which removes all registered listeners.
1437
+ * @returns A cleanup function which removes all registered listeners.
1434
1438
  */
1435
1439
  function finished(
1436
1440
  stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream,
@@ -1501,7 +1505,7 @@ declare module "stream" {
1501
1505
  * );
1502
1506
  * ```
1503
1507
  *
1504
- * The `pipeline` API provides a `promise version`.
1508
+ * The `pipeline` API provides a [`promise version`](https://nodejs.org/docs/latest-v20.x/api/stream.html#streampipelinesource-transforms-destination-options).
1505
1509
  *
1506
1510
  * `stream.pipeline()` will call `stream.destroy(err)` on all streams except:
1507
1511
  *
@@ -1541,7 +1545,7 @@ declare module "stream" {
1541
1545
  function pipeline<A extends PipelineSource<any>, B extends PipelineDestination<A, any>>(
1542
1546
  source: A,
1543
1547
  destination: B,
1544
- callback?: PipelineCallback<B>,
1548
+ callback: PipelineCallback<B>,
1545
1549
  ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1546
1550
  function pipeline<
1547
1551
  A extends PipelineSource<any>,
@@ -1551,7 +1555,7 @@ declare module "stream" {
1551
1555
  source: A,
1552
1556
  transform1: T1,
1553
1557
  destination: B,
1554
- callback?: PipelineCallback<B>,
1558
+ callback: PipelineCallback<B>,
1555
1559
  ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1556
1560
  function pipeline<
1557
1561
  A extends PipelineSource<any>,
@@ -1563,7 +1567,7 @@ declare module "stream" {
1563
1567
  transform1: T1,
1564
1568
  transform2: T2,
1565
1569
  destination: B,
1566
- callback?: PipelineCallback<B>,
1570
+ callback: PipelineCallback<B>,
1567
1571
  ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1568
1572
  function pipeline<
1569
1573
  A extends PipelineSource<any>,
@@ -1577,7 +1581,7 @@ declare module "stream" {
1577
1581
  transform2: T2,
1578
1582
  transform3: T3,
1579
1583
  destination: B,
1580
- callback?: PipelineCallback<B>,
1584
+ callback: PipelineCallback<B>,
1581
1585
  ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1582
1586
  function pipeline<
1583
1587
  A extends PipelineSource<any>,
@@ -1593,11 +1597,11 @@ declare module "stream" {
1593
1597
  transform3: T3,
1594
1598
  transform4: T4,
1595
1599
  destination: B,
1596
- callback?: PipelineCallback<B>,
1600
+ callback: PipelineCallback<B>,
1597
1601
  ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1598
1602
  function pipeline(
1599
1603
  streams: ReadonlyArray<NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream>,
1600
- callback?: (err: NodeJS.ErrnoException | null) => void,
1604
+ callback: (err: NodeJS.ErrnoException | null) => void,
1601
1605
  ): NodeJS.WritableStream;
1602
1606
  function pipeline(
1603
1607
  stream1: NodeJS.ReadableStream,
node/string_decoder.d.ts CHANGED
@@ -36,7 +36,7 @@
36
36
  * decoder.write(Buffer.from([0x82]));
37
37
  * console.log(decoder.end(Buffer.from([0xAC]))); // Prints: €
38
38
  * ```
39
- * @see [source](https://github.com/nodejs/node/blob/v20.12.2/lib/string_decoder.js)
39
+ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/string_decoder.js)
40
40
  */
41
41
  declare module "string_decoder" {
42
42
  class StringDecoder {