@netlify/plugin-nextjs 4.40.1 → 4.40.2

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