1{ 2 "type": "module", 3 "source": "doc/api/webstreams.md", 4 "modules": [ 5 { 6 "textRaw": "Web Streams API", 7 "name": "web_streams_api", 8 "introduced_in": "v16.5.0", 9 "meta": { 10 "added": [ 11 "v16.5.0" 12 ], 13 "changes": [ 14 { 15 "version": "v18.0.0", 16 "pr-url": "https://github.com/nodejs/node/pull/42225", 17 "description": "Use of this API no longer emit a runtime warning." 18 } 19 ] 20 }, 21 "stability": 1, 22 "stabilityText": "Experimental.", 23 "desc": "<p>An implementation of the <a href=\"https://streams.spec.whatwg.org/\">WHATWG Streams Standard</a>.</p>", 24 "modules": [ 25 { 26 "textRaw": "Overview", 27 "name": "overview", 28 "desc": "<p>The <a href=\"https://streams.spec.whatwg.org/\">WHATWG Streams Standard</a> (or \"web streams\") defines an API for handling\nstreaming data. It is similar to the Node.js <a href=\"stream.html\">Streams</a> API but emerged later\nand has become the \"standard\" API for streaming data across many JavaScript\nenvironments.</p>\n<p>There are three primary types of objects:</p>\n<ul>\n<li><code>ReadableStream</code> - Represents a source of streaming data.</li>\n<li><code>WritableStream</code> - Represents a destination for streaming data.</li>\n<li><code>TransformStream</code> - Represents an algorithm for transforming streaming data.</li>\n</ul>\n<h3>Example <code>ReadableStream</code></h3>\n<p>This example creates a simple <code>ReadableStream</code> that pushes the current\n<code>performance.now()</code> timestamp once every second forever. An async iterable\nis used to read the data from the stream.</p>\n<pre><code class=\"language-mjs\">import {\n ReadableStream,\n} from 'node:stream/web';\n\nimport {\n setInterval as every,\n} from 'node:timers/promises';\n\nimport {\n performance,\n} from 'node:perf_hooks';\n\nconst SECOND = 1000;\n\nconst stream = new ReadableStream({\n async start(controller) {\n for await (const _ of every(SECOND))\n controller.enqueue(performance.now());\n },\n});\n\nfor await (const value of stream)\n console.log(value);\n</code></pre>\n<pre><code class=\"language-cjs\">const {\n ReadableStream,\n} = require('node:stream/web');\n\nconst {\n setInterval: every,\n} = require('node:timers/promises');\n\nconst {\n performance,\n} = require('node:perf_hooks');\n\nconst SECOND = 1000;\n\nconst stream = new ReadableStream({\n async start(controller) {\n for await (const _ of every(SECOND))\n controller.enqueue(performance.now());\n },\n});\n\n(async () => {\n for await (const value of stream)\n console.log(value);\n})();\n</code></pre>", 29 "type": "module", 30 "displayName": "Overview" 31 }, 32 { 33 "textRaw": "API", 34 "name": "api", 35 "classes": [ 36 { 37 "textRaw": "Class: `ReadableStream`", 38 "type": "class", 39 "name": "ReadableStream", 40 "meta": { 41 "added": [ 42 "v16.5.0" 43 ], 44 "changes": [ 45 { 46 "version": "v18.0.0", 47 "pr-url": "https://github.com/nodejs/node/pull/42225", 48 "description": "This class is now exposed on the global object." 49 } 50 ] 51 }, 52 "properties": [ 53 { 54 "textRaw": "`locked` Type: {boolean} Set to `true` if there is an active reader for this {ReadableStream}.", 55 "type": "boolean", 56 "name": "Type", 57 "meta": { 58 "added": [ 59 "v16.5.0" 60 ], 61 "changes": [] 62 }, 63 "desc": "<p>The <code>readableStream.locked</code> property is <code>false</code> by default, and is\nswitched to <code>true</code> while there is an active reader consuming the\nstream's data.</p>", 64 "shortDesc": "Set to `true` if there is an active reader for this {ReadableStream}." 65 } 66 ], 67 "methods": [ 68 { 69 "textRaw": "`readableStream.cancel([reason])`", 70 "type": "method", 71 "name": "cancel", 72 "meta": { 73 "added": [ 74 "v16.5.0" 75 ], 76 "changes": [] 77 }, 78 "signatures": [ 79 { 80 "return": { 81 "textRaw": "Returns: A promise fulfilled with `undefined` once cancelation has been completed.", 82 "name": "return", 83 "desc": "A promise fulfilled with `undefined` once cancelation has been completed." 84 }, 85 "params": [ 86 { 87 "textRaw": "`reason` {any}", 88 "name": "reason", 89 "type": "any" 90 } 91 ] 92 } 93 ] 94 }, 95 { 96 "textRaw": "`readableStream.getReader([options])`", 97 "type": "method", 98 "name": "getReader", 99 "meta": { 100 "added": [ 101 "v16.5.0" 102 ], 103 "changes": [] 104 }, 105 "signatures": [ 106 { 107 "return": { 108 "textRaw": "Returns: {ReadableStreamDefaultReader|ReadableStreamBYOBReader}", 109 "name": "return", 110 "type": "ReadableStreamDefaultReader|ReadableStreamBYOBReader" 111 }, 112 "params": [ 113 { 114 "textRaw": "`options` {Object}", 115 "name": "options", 116 "type": "Object", 117 "options": [ 118 { 119 "textRaw": "`mode` {string} `'byob'` or `undefined`", 120 "name": "mode", 121 "type": "string", 122 "desc": "`'byob'` or `undefined`" 123 } 124 ] 125 } 126 ] 127 } 128 ], 129 "desc": "<pre><code class=\"language-mjs\">import { ReadableStream } from 'node:stream/web';\n\nconst stream = new ReadableStream();\n\nconst reader = stream.getReader();\n\nconsole.log(await reader.read());\n</code></pre>\n<pre><code class=\"language-cjs\">const { ReadableStream } = require('node:stream/web');\n\nconst stream = new ReadableStream();\n\nconst reader = stream.getReader();\n\nreader.read().then(console.log);\n</code></pre>\n<p>Causes the <code>readableStream.locked</code> to be <code>true</code>.</p>" 130 }, 131 { 132 "textRaw": "`readableStream.pipeThrough(transform[, options])`", 133 "type": "method", 134 "name": "pipeThrough", 135 "meta": { 136 "added": [ 137 "v16.5.0" 138 ], 139 "changes": [] 140 }, 141 "signatures": [ 142 { 143 "return": { 144 "textRaw": "Returns: {ReadableStream} From `transform.readable`.", 145 "name": "return", 146 "type": "ReadableStream", 147 "desc": "From `transform.readable`." 148 }, 149 "params": [ 150 { 151 "textRaw": "`transform` {Object}", 152 "name": "transform", 153 "type": "Object", 154 "options": [ 155 { 156 "textRaw": "`readable` {ReadableStream} The `ReadableStream` to which `transform.writable` will push the potentially modified data is receives from this `ReadableStream`.", 157 "name": "readable", 158 "type": "ReadableStream", 159 "desc": "The `ReadableStream` to which `transform.writable` will push the potentially modified data is receives from this `ReadableStream`." 160 }, 161 { 162 "textRaw": "`writable` {WritableStream} The `WritableStream` to which this `ReadableStream`'s data will be written.", 163 "name": "writable", 164 "type": "WritableStream", 165 "desc": "The `WritableStream` to which this `ReadableStream`'s data will be written." 166 } 167 ] 168 }, 169 { 170 "textRaw": "`options` {Object}", 171 "name": "options", 172 "type": "Object", 173 "options": [ 174 { 175 "textRaw": "`preventAbort` {boolean} When `true`, errors in this `ReadableStream` will not cause `transform.writable` to be aborted.", 176 "name": "preventAbort", 177 "type": "boolean", 178 "desc": "When `true`, errors in this `ReadableStream` will not cause `transform.writable` to be aborted." 179 }, 180 { 181 "textRaw": "`preventCancel` {boolean} When `true`, errors in the destination `transform.writable` do not cause this `ReadableStream` to be canceled.", 182 "name": "preventCancel", 183 "type": "boolean", 184 "desc": "When `true`, errors in the destination `transform.writable` do not cause this `ReadableStream` to be canceled." 185 }, 186 { 187 "textRaw": "`preventClose` {boolean} When `true`, closing this `ReadableStream` does not cause `transform.writable` to be closed.", 188 "name": "preventClose", 189 "type": "boolean", 190 "desc": "When `true`, closing this `ReadableStream` does not cause `transform.writable` to be closed." 191 }, 192 { 193 "textRaw": "`signal` {AbortSignal} Allows the transfer of data to be canceled using an {AbortController}.", 194 "name": "signal", 195 "type": "AbortSignal", 196 "desc": "Allows the transfer of data to be canceled using an {AbortController}." 197 } 198 ] 199 } 200 ] 201 } 202 ], 203 "desc": "<p>Connects this <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> to the pair of <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> and\n<a href=\"webstreams.html#class-writablestream\" class=\"type\"><WritableStream></a> provided in the <code>transform</code> argument such that the\ndata from this <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> is written in to <code>transform.writable</code>,\npossibly transformed, then pushed to <code>transform.readable</code>. Once the\npipeline is configured, <code>transform.readable</code> is returned.</p>\n<p>Causes the <code>readableStream.locked</code> to be <code>true</code> while the pipe operation\nis active.</p>\n<pre><code class=\"language-mjs\">import {\n ReadableStream,\n TransformStream,\n} from 'node:stream/web';\n\nconst stream = new ReadableStream({\n start(controller) {\n controller.enqueue('a');\n },\n});\n\nconst transform = new TransformStream({\n transform(chunk, controller) {\n controller.enqueue(chunk.toUpperCase());\n },\n});\n\nconst transformedStream = stream.pipeThrough(transform);\n\nfor await (const chunk of transformedStream)\n console.log(chunk);\n</code></pre>\n<pre><code class=\"language-cjs\">const {\n ReadableStream,\n TransformStream,\n} = require('node:stream/web');\n\nconst stream = new ReadableStream({\n start(controller) {\n controller.enqueue('a');\n },\n});\n\nconst transform = new TransformStream({\n transform(chunk, controller) {\n controller.enqueue(chunk.toUpperCase());\n },\n});\n\nconst transformedStream = stream.pipeThrough(transform);\n\n(async () => {\n for await (const chunk of transformedStream)\n console.log(chunk);\n})();\n</code></pre>" 204 }, 205 { 206 "textRaw": "`readableStream.pipeTo(destination[, options])`", 207 "type": "method", 208 "name": "pipeTo", 209 "meta": { 210 "added": [ 211 "v16.5.0" 212 ], 213 "changes": [] 214 }, 215 "signatures": [ 216 { 217 "return": { 218 "textRaw": "Returns: A promise fulfilled with `undefined`", 219 "name": "return", 220 "desc": "A promise fulfilled with `undefined`" 221 }, 222 "params": [ 223 { 224 "textRaw": "`destination` {WritableStream} A {WritableStream} to which this `ReadableStream`'s data will be written.", 225 "name": "destination", 226 "type": "WritableStream", 227 "desc": "A {WritableStream} to which this `ReadableStream`'s data will be written." 228 }, 229 { 230 "textRaw": "`options` {Object}", 231 "name": "options", 232 "type": "Object", 233 "options": [ 234 { 235 "textRaw": "`preventAbort` {boolean} When `true`, errors in this `ReadableStream` will not cause `destination` to be aborted.", 236 "name": "preventAbort", 237 "type": "boolean", 238 "desc": "When `true`, errors in this `ReadableStream` will not cause `destination` to be aborted." 239 }, 240 { 241 "textRaw": "`preventCancel` {boolean} When `true`, errors in the `destination` will not cause this `ReadableStream` to be canceled.", 242 "name": "preventCancel", 243 "type": "boolean", 244 "desc": "When `true`, errors in the `destination` will not cause this `ReadableStream` to be canceled." 245 }, 246 { 247 "textRaw": "`preventClose` {boolean} When `true`, closing this `ReadableStream` does not cause `destination` to be closed.", 248 "name": "preventClose", 249 "type": "boolean", 250 "desc": "When `true`, closing this `ReadableStream` does not cause `destination` to be closed." 251 }, 252 { 253 "textRaw": "`signal` {AbortSignal} Allows the transfer of data to be canceled using an {AbortController}.", 254 "name": "signal", 255 "type": "AbortSignal", 256 "desc": "Allows the transfer of data to be canceled using an {AbortController}." 257 } 258 ] 259 } 260 ] 261 } 262 ], 263 "desc": "<p>Causes the <code>readableStream.locked</code> to be <code>true</code> while the pipe operation\nis active.</p>" 264 }, 265 { 266 "textRaw": "`readableStream.tee()`", 267 "type": "method", 268 "name": "tee", 269 "meta": { 270 "added": [ 271 "v16.5.0" 272 ], 273 "changes": [ 274 { 275 "version": "v18.10.0", 276 "pr-url": "https://github.com/nodejs/node/pull/44505", 277 "description": "Support teeing a readable byte stream." 278 } 279 ] 280 }, 281 "signatures": [ 282 { 283 "return": { 284 "textRaw": "Returns: {ReadableStream\\[]}", 285 "name": "return", 286 "type": "ReadableStream\\[]" 287 }, 288 "params": [] 289 } 290 ], 291 "desc": "<p>Returns a pair of new <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> instances to which this\n<code>ReadableStream</code>'s data will be forwarded. Each will receive the\nsame data.</p>\n<p>Causes the <code>readableStream.locked</code> to be <code>true</code>.</p>" 292 }, 293 { 294 "textRaw": "`readableStream.values([options])`", 295 "type": "method", 296 "name": "values", 297 "meta": { 298 "added": [ 299 "v16.5.0" 300 ], 301 "changes": [] 302 }, 303 "signatures": [ 304 { 305 "params": [ 306 { 307 "textRaw": "`options` {Object}", 308 "name": "options", 309 "type": "Object", 310 "options": [ 311 { 312 "textRaw": "`preventCancel` {boolean} When `true`, prevents the {ReadableStream} from being closed when the async iterator abruptly terminates. **Default**: `false`.", 313 "name": "preventCancel", 314 "type": "boolean", 315 "desc": "When `true`, prevents the {ReadableStream} from being closed when the async iterator abruptly terminates. **Default**: `false`." 316 } 317 ] 318 } 319 ] 320 } 321 ], 322 "desc": "<p>Creates and returns an async iterator usable for consuming this\n<code>ReadableStream</code>'s data.</p>\n<p>Causes the <code>readableStream.locked</code> to be <code>true</code> while the async iterator\nis active.</p>\n<pre><code class=\"language-mjs\">import { Buffer } from 'node:buffer';\n\nconst stream = new ReadableStream(getSomeSource());\n\nfor await (const chunk of stream.values({ preventCancel: true }))\n console.log(Buffer.from(chunk).toString());\n</code></pre>" 323 } 324 ], 325 "modules": [ 326 { 327 "textRaw": "Async Iteration", 328 "name": "async_iteration", 329 "desc": "<p>The <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> object supports the async iterator protocol using\n<code>for await</code> syntax.</p>\n<pre><code class=\"language-mjs\">import { Buffer } from 'node:buffer';\n\nconst stream = new ReadableStream(getSomeSource());\n\nfor await (const chunk of stream)\n console.log(Buffer.from(chunk).toString());\n</code></pre>\n<p>The async iterator will consume the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> until it terminates.</p>\n<p>By default, if the async iterator exits early (via either a <code>break</code>,\n<code>return</code>, or a <code>throw</code>), the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> will be closed. To prevent\nautomatic closing of the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a>, use the <code>readableStream.values()</code>\nmethod to acquire the async iterator and set the <code>preventCancel</code> option to\n<code>true</code>.</p>\n<p>The <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> must not be locked (that is, it must not have an existing\nactive reader). During the async iteration, the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> will be locked.</p>", 330 "type": "module", 331 "displayName": "Async Iteration" 332 }, 333 { 334 "textRaw": "Transferring with `postMessage()`", 335 "name": "transferring_with_`postmessage()`", 336 "desc": "<p>A <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> instance can be transferred using a <a href=\"worker_threads.html#class-messageport\" class=\"type\"><MessagePort></a>.</p>\n<pre><code class=\"language-js\">const stream = new ReadableStream(getReadableSourceSomehow());\n\nconst { port1, port2 } = new MessageChannel();\n\nport1.onmessage = ({ data }) => {\n data.getReader().read().then((chunk) => {\n console.log(chunk);\n });\n};\n\nport2.postMessage(stream, [stream]);\n</code></pre>", 337 "type": "module", 338 "displayName": "Transferring with `postMessage()`" 339 } 340 ], 341 "signatures": [ 342 { 343 "params": [], 344 "desc": "<!--lint disable maximum-line-length remark-lint-->\n<ul>\n<li><code>underlyingSource</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\"><Object></a>\n<ul>\n<li><code>start</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\" class=\"type\"><Function></a> A user-defined function that is invoked immediately when\nthe <code>ReadableStream</code> is created.\n<ul>\n<li><code>controller</code> <a href=\"webstreams.html#class-readablestreamdefaultcontroller\" class=\"type\"><ReadableStreamDefaultController></a> | <a href=\"webstreams.html#class-readablebytestreamcontroller\" class=\"type\"><ReadableByteStreamController></a></li>\n<li>Returns: <code>undefined</code> or a promise fulfilled with <code>undefined</code>.</li>\n</ul>\n</li>\n<li><code>pull</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\" class=\"type\"><Function></a> A user-defined function that is called repeatedly when the\n<code>ReadableStream</code> internal queue is not full. The operation may be sync or\nasync. If async, the function will not be called again until the previously\nreturned promise is fulfilled.\n<ul>\n<li><code>controller</code> <a href=\"webstreams.html#class-readablestreamdefaultcontroller\" class=\"type\"><ReadableStreamDefaultController></a> | <a href=\"webstreams.html#class-readablebytestreamcontroller\" class=\"type\"><ReadableByteStreamController></a></li>\n<li>Returns: A promise fulfilled with <code>undefined</code>.</li>\n</ul>\n</li>\n<li><code>cancel</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\" class=\"type\"><Function></a> A user-defined function that is called when the\n<code>ReadableStream</code> is canceled.\n<ul>\n<li><code>reason</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types\" class=\"type\"><any></a></li>\n<li>Returns: A promise fulfilled with <code>undefined</code>.</li>\n</ul>\n</li>\n<li><code>type</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string></a> Must be <code>'bytes'</code> or <code>undefined</code>.</li>\n<li><code>autoAllocateChunkSize</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> Used only when <code>type</code> is equal to\n<code>'bytes'</code>. When set to a non-zero value a view buffer is automatically\nallocated to <code>ReadableByteStreamController.byobRequest</code>. When not set\none must use stream's internal queues to transfer data via the default\nreader <code>ReadableStreamDefaultReader</code>.</li>\n</ul>\n</li>\n<li><code>strategy</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\"><Object></a>\n<ul>\n<li><code>highWaterMark</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a> The maximum internal queue size before backpressure\nis applied.</li>\n<li><code>size</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\" class=\"type\"><Function></a> A user-defined function used to identify the size of each\nchunk of data.\n<ul>\n<li><code>chunk</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types\" class=\"type\"><any></a></li>\n<li>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a></li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n<!--lint enable maximum-line-length remark-lint-->" 345 } 346 ] 347 }, 348 { 349 "textRaw": "Class: `ReadableStreamDefaultReader`", 350 "type": "class", 351 "name": "ReadableStreamDefaultReader", 352 "meta": { 353 "added": [ 354 "v16.5.0" 355 ], 356 "changes": [ 357 { 358 "version": "v18.0.0", 359 "pr-url": "https://github.com/nodejs/node/pull/42225", 360 "description": "This class is now exposed on the global object." 361 } 362 ] 363 }, 364 "desc": "<p>By default, calling <code>readableStream.getReader()</code> with no arguments\nwill return an instance of <code>ReadableStreamDefaultReader</code>. The default\nreader treats the chunks of data passed through the stream as opaque\nvalues, which allows the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> to work with generally any\nJavaScript value.</p>", 365 "methods": [ 366 { 367 "textRaw": "`readableStreamDefaultReader.cancel([reason])`", 368 "type": "method", 369 "name": "cancel", 370 "meta": { 371 "added": [ 372 "v16.5.0" 373 ], 374 "changes": [] 375 }, 376 "signatures": [ 377 { 378 "return": { 379 "textRaw": "Returns: A promise fulfilled with `undefined`.", 380 "name": "return", 381 "desc": "A promise fulfilled with `undefined`." 382 }, 383 "params": [ 384 { 385 "textRaw": "`reason` {any}", 386 "name": "reason", 387 "type": "any" 388 } 389 ] 390 } 391 ], 392 "desc": "<p>Cancels the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> and returns a promise that is fulfilled\nwhen the underlying stream has been canceled.</p>" 393 }, 394 { 395 "textRaw": "`readableStreamDefaultReader.read()`", 396 "type": "method", 397 "name": "read", 398 "meta": { 399 "added": [ 400 "v16.5.0" 401 ], 402 "changes": [] 403 }, 404 "signatures": [ 405 { 406 "return": { 407 "textRaw": "Returns: A promise fulfilled with an object:", 408 "name": "return", 409 "desc": "A promise fulfilled with an object:", 410 "options": [ 411 { 412 "textRaw": "`value` {ArrayBuffer}", 413 "name": "value", 414 "type": "ArrayBuffer" 415 }, 416 { 417 "textRaw": "`done` {boolean}", 418 "name": "done", 419 "type": "boolean" 420 } 421 ] 422 }, 423 "params": [] 424 } 425 ], 426 "desc": "<p>Requests the next chunk of data from the underlying <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a>\nand returns a promise that is fulfilled with the data once it is\navailable.</p>" 427 }, 428 { 429 "textRaw": "`readableStreamDefaultReader.releaseLock()`", 430 "type": "method", 431 "name": "releaseLock", 432 "meta": { 433 "added": [ 434 "v16.5.0" 435 ], 436 "changes": [] 437 }, 438 "signatures": [ 439 { 440 "params": [] 441 } 442 ], 443 "desc": "<p>Releases this reader's lock on the underlying <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a>.</p>" 444 } 445 ], 446 "properties": [ 447 { 448 "textRaw": "`closed` Type: {Promise} Fulfilled with `undefined` when the associated {ReadableStream} is closed or rejected if the stream errors or the reader's lock is released before the stream finishes closing.", 449 "type": "Promise", 450 "name": "Type", 451 "meta": { 452 "added": [ 453 "v16.5.0" 454 ], 455 "changes": [] 456 }, 457 "desc": "Fulfilled with `undefined` when the associated {ReadableStream} is closed or rejected if the stream errors or the reader's lock is released before the stream finishes closing." 458 } 459 ], 460 "signatures": [ 461 { 462 "params": [ 463 { 464 "textRaw": "`stream` {ReadableStream}", 465 "name": "stream", 466 "type": "ReadableStream" 467 } 468 ], 469 "desc": "<p>Creates a new <a href=\"webstreams.html#class-readablestreamdefaultreader\" class=\"type\"><ReadableStreamDefaultReader></a> that is locked to the\ngiven <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a>.</p>" 470 } 471 ] 472 }, 473 { 474 "textRaw": "Class: `ReadableStreamBYOBReader`", 475 "type": "class", 476 "name": "ReadableStreamBYOBReader", 477 "meta": { 478 "added": [ 479 "v16.5.0" 480 ], 481 "changes": [ 482 { 483 "version": "v18.0.0", 484 "pr-url": "https://github.com/nodejs/node/pull/42225", 485 "description": "This class is now exposed on the global object." 486 } 487 ] 488 }, 489 "desc": "<p>The <code>ReadableStreamBYOBReader</code> is an alternative consumer for\nbyte-oriented <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a>s (those that are created with\n<code>underlyingSource.type</code> set equal to <code>'bytes'</code> when the\n<code>ReadableStream</code> was created).</p>\n<p>The <code>BYOB</code> is short for \"bring your own buffer\". This is a\npattern that allows for more efficient reading of byte-oriented\ndata that avoids extraneous copying.</p>\n<pre><code class=\"language-mjs\">import {\n open,\n} from 'node:fs/promises';\n\nimport {\n ReadableStream,\n} from 'node:stream/web';\n\nimport { Buffer } from 'node:buffer';\n\nclass Source {\n type = 'bytes';\n autoAllocateChunkSize = 1024;\n\n async start(controller) {\n this.file = await open(new URL(import.meta.url));\n this.controller = controller;\n }\n\n async pull(controller) {\n const view = controller.byobRequest?.view;\n const {\n bytesRead,\n } = await this.file.read({\n buffer: view,\n offset: view.byteOffset,\n length: view.byteLength,\n });\n\n if (bytesRead === 0) {\n await this.file.close();\n this.controller.close();\n }\n controller.byobRequest.respond(bytesRead);\n }\n}\n\nconst stream = new ReadableStream(new Source());\n\nasync function read(stream) {\n const reader = stream.getReader({ mode: 'byob' });\n\n const chunks = [];\n let result;\n do {\n result = await reader.read(Buffer.alloc(100));\n if (result.value !== undefined)\n chunks.push(Buffer.from(result.value));\n } while (!result.done);\n\n return Buffer.concat(chunks);\n}\n\nconst data = await read(stream);\nconsole.log(Buffer.from(data).toString());\n</code></pre>", 490 "methods": [ 491 { 492 "textRaw": "`readableStreamBYOBReader.cancel([reason])`", 493 "type": "method", 494 "name": "cancel", 495 "meta": { 496 "added": [ 497 "v16.5.0" 498 ], 499 "changes": [] 500 }, 501 "signatures": [ 502 { 503 "return": { 504 "textRaw": "Returns: A promise fulfilled with `undefined`.", 505 "name": "return", 506 "desc": "A promise fulfilled with `undefined`." 507 }, 508 "params": [ 509 { 510 "textRaw": "`reason` {any}", 511 "name": "reason", 512 "type": "any" 513 } 514 ] 515 } 516 ], 517 "desc": "<p>Cancels the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> and returns a promise that is fulfilled\nwhen the underlying stream has been canceled.</p>" 518 }, 519 { 520 "textRaw": "`readableStreamBYOBReader.read(view)`", 521 "type": "method", 522 "name": "read", 523 "meta": { 524 "added": [ 525 "v16.5.0" 526 ], 527 "changes": [] 528 }, 529 "signatures": [ 530 { 531 "return": { 532 "textRaw": "Returns: A promise fulfilled with an object:", 533 "name": "return", 534 "desc": "A promise fulfilled with an object:", 535 "options": [ 536 { 537 "textRaw": "`value` {ArrayBuffer}", 538 "name": "value", 539 "type": "ArrayBuffer" 540 }, 541 { 542 "textRaw": "`done` {boolean}", 543 "name": "done", 544 "type": "boolean" 545 } 546 ] 547 }, 548 "params": [ 549 { 550 "textRaw": "`view` {Buffer|TypedArray|DataView}", 551 "name": "view", 552 "type": "Buffer|TypedArray|DataView" 553 } 554 ] 555 } 556 ], 557 "desc": "<p>Requests the next chunk of data from the underlying <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a>\nand returns a promise that is fulfilled with the data once it is\navailable.</p>\n<p>Do not pass a pooled <a href=\"buffer.html#class-buffer\" class=\"type\"><Buffer></a> object instance in to this method.\nPooled <code>Buffer</code> objects are created using <code>Buffer.allocUnsafe()</code>,\nor <code>Buffer.from()</code>, or are often returned by various <code>node:fs</code> module\ncallbacks. These types of <code>Buffer</code>s use a shared underlying\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer\" class=\"type\"><ArrayBuffer></a> object that contains all of the data from all of\nthe pooled <code>Buffer</code> instances. When a <code>Buffer</code>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\" class=\"type\"><TypedArray></a>,\nor <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView\" class=\"type\"><DataView></a> is passed in to <code>readableStreamBYOBReader.read()</code>,\nthe view's underlying <code>ArrayBuffer</code> is <em>detached</em>, invalidating\nall existing views that may exist on that <code>ArrayBuffer</code>. This\ncan have disastrous consequences for your application.</p>" 558 }, 559 { 560 "textRaw": "`readableStreamBYOBReader.releaseLock()`", 561 "type": "method", 562 "name": "releaseLock", 563 "meta": { 564 "added": [ 565 "v16.5.0" 566 ], 567 "changes": [] 568 }, 569 "signatures": [ 570 { 571 "params": [] 572 } 573 ], 574 "desc": "<p>Releases this reader's lock on the underlying <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a>.</p>" 575 } 576 ], 577 "properties": [ 578 { 579 "textRaw": "`closed` Type: {Promise} Fulfilled with `undefined` when the associated {ReadableStream} is closed or rejected if the stream errors or the reader's lock is released before the stream finishes closing.", 580 "type": "Promise", 581 "name": "Type", 582 "meta": { 583 "added": [ 584 "v16.5.0" 585 ], 586 "changes": [] 587 }, 588 "desc": "Fulfilled with `undefined` when the associated {ReadableStream} is closed or rejected if the stream errors or the reader's lock is released before the stream finishes closing." 589 } 590 ], 591 "signatures": [ 592 { 593 "params": [ 594 { 595 "textRaw": "`stream` {ReadableStream}", 596 "name": "stream", 597 "type": "ReadableStream" 598 } 599 ], 600 "desc": "<p>Creates a new <code>ReadableStreamBYOBReader</code> that is locked to the\ngiven <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a>.</p>" 601 } 602 ] 603 }, 604 { 605 "textRaw": "Class: `ReadableStreamDefaultController`", 606 "type": "class", 607 "name": "ReadableStreamDefaultController", 608 "meta": { 609 "added": [ 610 "v16.5.0" 611 ], 612 "changes": [] 613 }, 614 "desc": "<p>Every <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> has a controller that is responsible for\nthe internal state and management of the stream's queue. The\n<code>ReadableStreamDefaultController</code> is the default controller\nimplementation for <code>ReadableStream</code>s that are not byte-oriented.</p>", 615 "methods": [ 616 { 617 "textRaw": "`readableStreamDefaultController.close()`", 618 "type": "method", 619 "name": "close", 620 "meta": { 621 "added": [ 622 "v16.5.0" 623 ], 624 "changes": [] 625 }, 626 "signatures": [ 627 { 628 "params": [] 629 } 630 ], 631 "desc": "<p>Closes the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> to which this controller is associated.</p>" 632 }, 633 { 634 "textRaw": "`readableStreamDefaultController.enqueue([chunk])`", 635 "type": "method", 636 "name": "enqueue", 637 "meta": { 638 "added": [ 639 "v16.5.0" 640 ], 641 "changes": [] 642 }, 643 "signatures": [ 644 { 645 "params": [ 646 { 647 "textRaw": "`chunk` {any}", 648 "name": "chunk", 649 "type": "any" 650 } 651 ] 652 } 653 ], 654 "desc": "<p>Appends a new chunk of data to the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a>'s queue.</p>" 655 }, 656 { 657 "textRaw": "`readableStreamDefaultController.error([error])`", 658 "type": "method", 659 "name": "error", 660 "meta": { 661 "added": [ 662 "v16.5.0" 663 ], 664 "changes": [] 665 }, 666 "signatures": [ 667 { 668 "params": [ 669 { 670 "textRaw": "`error` {any}", 671 "name": "error", 672 "type": "any" 673 } 674 ] 675 } 676 ], 677 "desc": "<p>Signals an error that causes the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> to error and close.</p>" 678 } 679 ], 680 "properties": [ 681 { 682 "textRaw": "`desiredSize` Type: {number}", 683 "type": "number", 684 "name": "Type", 685 "meta": { 686 "added": [ 687 "v16.5.0" 688 ], 689 "changes": [] 690 }, 691 "desc": "<p>Returns the amount of data remaining to fill the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a>'s\nqueue.</p>" 692 } 693 ] 694 }, 695 { 696 "textRaw": "Class: `ReadableByteStreamController`", 697 "type": "class", 698 "name": "ReadableByteStreamController", 699 "meta": { 700 "added": [ 701 "v16.5.0" 702 ], 703 "changes": [ 704 { 705 "version": "v18.10.0", 706 "pr-url": "https://github.com/nodejs/node/pull/44702", 707 "description": "Support handling a BYOB pull request from a released reader." 708 } 709 ] 710 }, 711 "desc": "<p>Every <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> has a controller that is responsible for\nthe internal state and management of the stream's queue. The\n<code>ReadableByteStreamController</code> is for byte-oriented <code>ReadableStream</code>s.</p>", 712 "properties": [ 713 { 714 "textRaw": "`byobRequest` Type: {ReadableStreamBYOBRequest}", 715 "type": "ReadableStreamBYOBRequest", 716 "name": "Type", 717 "meta": { 718 "added": [ 719 "v16.5.0" 720 ], 721 "changes": [] 722 }, 723 "desc": "<p>Returns the amount of data remaining to fill the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a>'s\nqueue.</p>" 724 }, 725 { 726 "textRaw": "`desiredSize` Type: {number}", 727 "type": "number", 728 "name": "Type", 729 "meta": { 730 "added": [ 731 "v16.5.0" 732 ], 733 "changes": [] 734 }, 735 "desc": "<p>Returns the amount of data remaining to fill the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a>'s\nqueue.</p>" 736 } 737 ], 738 "methods": [ 739 { 740 "textRaw": "`readableByteStreamController.close()`", 741 "type": "method", 742 "name": "close", 743 "meta": { 744 "added": [ 745 "v16.5.0" 746 ], 747 "changes": [] 748 }, 749 "signatures": [ 750 { 751 "params": [] 752 } 753 ], 754 "desc": "<p>Closes the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> to which this controller is associated.</p>" 755 }, 756 { 757 "textRaw": "`readableByteStreamController.enqueue(chunk)`", 758 "type": "method", 759 "name": "enqueue", 760 "meta": { 761 "added": [ 762 "v16.5.0" 763 ], 764 "changes": [] 765 }, 766 "signatures": [ 767 { 768 "params": [ 769 { 770 "textRaw": "`chunk`: {Buffer|TypedArray|DataView}", 771 "name": "chunk", 772 "type": "Buffer|TypedArray|DataView" 773 } 774 ] 775 } 776 ], 777 "desc": "<p>Appends a new chunk of data to the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a>'s queue.</p>" 778 }, 779 { 780 "textRaw": "`readableByteStreamController.error([error])`", 781 "type": "method", 782 "name": "error", 783 "meta": { 784 "added": [ 785 "v16.5.0" 786 ], 787 "changes": [] 788 }, 789 "signatures": [ 790 { 791 "params": [ 792 { 793 "textRaw": "`error` {any}", 794 "name": "error", 795 "type": "any" 796 } 797 ] 798 } 799 ], 800 "desc": "<p>Signals an error that causes the <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> to error and close.</p>" 801 } 802 ] 803 }, 804 { 805 "textRaw": "Class: `ReadableStreamBYOBRequest`", 806 "type": "class", 807 "name": "ReadableStreamBYOBRequest", 808 "meta": { 809 "added": [ 810 "v16.5.0" 811 ], 812 "changes": [ 813 { 814 "version": "v18.0.0", 815 "pr-url": "https://github.com/nodejs/node/pull/42225", 816 "description": "This class is now exposed on the global object." 817 } 818 ] 819 }, 820 "desc": "<p>When using <code>ReadableByteStreamController</code> in byte-oriented\nstreams, and when using the <code>ReadableStreamBYOBReader</code>,\nthe <code>readableByteStreamController.byobRequest</code> property\nprovides access to a <code>ReadableStreamBYOBRequest</code> instance\nthat represents the current read request. The object\nis used to gain access to the <code>ArrayBuffer</code>/<code>TypedArray</code>\nthat has been provided for the read request to fill,\nand provides methods for signaling that the data has\nbeen provided.</p>", 821 "methods": [ 822 { 823 "textRaw": "`readableStreamBYOBRequest.respond(bytesWritten)`", 824 "type": "method", 825 "name": "respond", 826 "meta": { 827 "added": [ 828 "v16.5.0" 829 ], 830 "changes": [] 831 }, 832 "signatures": [ 833 { 834 "params": [ 835 { 836 "textRaw": "`bytesWritten` {number}", 837 "name": "bytesWritten", 838 "type": "number" 839 } 840 ] 841 } 842 ], 843 "desc": "<p>Signals that a <code>bytesWritten</code> number of bytes have been written\nto <code>readableStreamBYOBRequest.view</code>.</p>" 844 }, 845 { 846 "textRaw": "`readableStreamBYOBRequest.respondWithNewView(view)`", 847 "type": "method", 848 "name": "respondWithNewView", 849 "meta": { 850 "added": [ 851 "v16.5.0" 852 ], 853 "changes": [] 854 }, 855 "signatures": [ 856 { 857 "params": [ 858 { 859 "textRaw": "`view` {Buffer|TypedArray|DataView}", 860 "name": "view", 861 "type": "Buffer|TypedArray|DataView" 862 } 863 ] 864 } 865 ], 866 "desc": "<p>Signals that the request has been fulfilled with bytes written\nto a new <code>Buffer</code>, <code>TypedArray</code>, or <code>DataView</code>.</p>" 867 } 868 ], 869 "properties": [ 870 { 871 "textRaw": "`view` Type: {Buffer|TypedArray|DataView}", 872 "type": "Buffer|TypedArray|DataView", 873 "name": "Type", 874 "meta": { 875 "added": [ 876 "v16.5.0" 877 ], 878 "changes": [] 879 } 880 } 881 ] 882 }, 883 { 884 "textRaw": "Class: `WritableStream`", 885 "type": "class", 886 "name": "WritableStream", 887 "meta": { 888 "added": [ 889 "v16.5.0" 890 ], 891 "changes": [ 892 { 893 "version": "v18.0.0", 894 "pr-url": "https://github.com/nodejs/node/pull/42225", 895 "description": "This class is now exposed on the global object." 896 } 897 ] 898 }, 899 "desc": "<p>The <code>WritableStream</code> is a destination to which stream data is sent.</p>\n<pre><code class=\"language-mjs\">import {\n WritableStream,\n} from 'node:stream/web';\n\nconst stream = new WritableStream({\n write(chunk) {\n console.log(chunk);\n },\n});\n\nawait stream.getWriter().write('Hello World');\n</code></pre>", 900 "methods": [ 901 { 902 "textRaw": "`writableStream.abort([reason])`", 903 "type": "method", 904 "name": "abort", 905 "meta": { 906 "added": [ 907 "v16.5.0" 908 ], 909 "changes": [] 910 }, 911 "signatures": [ 912 { 913 "return": { 914 "textRaw": "Returns: A promise fulfilled with `undefined`.", 915 "name": "return", 916 "desc": "A promise fulfilled with `undefined`." 917 }, 918 "params": [ 919 { 920 "textRaw": "`reason` {any}", 921 "name": "reason", 922 "type": "any" 923 } 924 ] 925 } 926 ], 927 "desc": "<p>Abruptly terminates the <code>WritableStream</code>. All queued writes will be\ncanceled with their associated promises rejected.</p>" 928 }, 929 { 930 "textRaw": "`writableStream.close()`", 931 "type": "method", 932 "name": "close", 933 "meta": { 934 "added": [ 935 "v16.5.0" 936 ], 937 "changes": [] 938 }, 939 "signatures": [ 940 { 941 "return": { 942 "textRaw": "Returns: A promise fulfilled with `undefined`.", 943 "name": "return", 944 "desc": "A promise fulfilled with `undefined`." 945 }, 946 "params": [] 947 } 948 ], 949 "desc": "<p>Closes the <code>WritableStream</code> when no additional writes are expected.</p>" 950 }, 951 { 952 "textRaw": "`writableStream.getWriter()`", 953 "type": "method", 954 "name": "getWriter", 955 "meta": { 956 "added": [ 957 "v16.5.0" 958 ], 959 "changes": [] 960 }, 961 "signatures": [ 962 { 963 "return": { 964 "textRaw": "Returns: {WritableStreamDefaultWriter}", 965 "name": "return", 966 "type": "WritableStreamDefaultWriter" 967 }, 968 "params": [] 969 } 970 ], 971 "desc": "<p>Creates and returns a new writer instance that can be used to write\ndata into the <code>WritableStream</code>.</p>" 972 } 973 ], 974 "properties": [ 975 { 976 "textRaw": "`locked` Type: {boolean}", 977 "type": "boolean", 978 "name": "Type", 979 "meta": { 980 "added": [ 981 "v16.5.0" 982 ], 983 "changes": [] 984 }, 985 "desc": "<p>The <code>writableStream.locked</code> property is <code>false</code> by default, and is\nswitched to <code>true</code> while there is an active writer attached to this\n<code>WritableStream</code>.</p>" 986 } 987 ], 988 "modules": [ 989 { 990 "textRaw": "Transferring with postMessage()", 991 "name": "transferring_with_postmessage()", 992 "desc": "<p>A <a href=\"webstreams.html#class-writablestream\" class=\"type\"><WritableStream></a> instance can be transferred using a <a href=\"worker_threads.html#class-messageport\" class=\"type\"><MessagePort></a>.</p>\n<pre><code class=\"language-js\">const stream = new WritableStream(getWritableSinkSomehow());\n\nconst { port1, port2 } = new MessageChannel();\n\nport1.onmessage = ({ data }) => {\n data.getWriter().write('hello');\n};\n\nport2.postMessage(stream, [stream]);\n</code></pre>", 993 "type": "module", 994 "displayName": "Transferring with postMessage()" 995 } 996 ], 997 "signatures": [ 998 { 999 "params": [ 1000 { 1001 "textRaw": "`underlyingSink` {Object}", 1002 "name": "underlyingSink", 1003 "type": "Object", 1004 "options": [ 1005 { 1006 "textRaw": "`start` {Function} A user-defined function that is invoked immediately when the `WritableStream` is created.", 1007 "name": "start", 1008 "type": "Function", 1009 "desc": "A user-defined function that is invoked immediately when the `WritableStream` is created.", 1010 "options": [ 1011 { 1012 "textRaw": "`controller` {WritableStreamDefaultController}", 1013 "name": "controller", 1014 "type": "WritableStreamDefaultController" 1015 }, 1016 { 1017 "textRaw": "Returns: `undefined` or a promise fulfilled with `undefined`.", 1018 "name": "return", 1019 "desc": "`undefined` or a promise fulfilled with `undefined`." 1020 } 1021 ] 1022 }, 1023 { 1024 "textRaw": "`write` {Function} A user-defined function that is invoked when a chunk of data has been written to the `WritableStream`.", 1025 "name": "write", 1026 "type": "Function", 1027 "desc": "A user-defined function that is invoked when a chunk of data has been written to the `WritableStream`.", 1028 "options": [ 1029 { 1030 "textRaw": "`chunk` {any}", 1031 "name": "chunk", 1032 "type": "any" 1033 }, 1034 { 1035 "textRaw": "`controller` {WritableStreamDefaultController}", 1036 "name": "controller", 1037 "type": "WritableStreamDefaultController" 1038 }, 1039 { 1040 "textRaw": "Returns: A promise fulfilled with `undefined`.", 1041 "name": "return", 1042 "desc": "A promise fulfilled with `undefined`." 1043 } 1044 ] 1045 }, 1046 { 1047 "textRaw": "`close` {Function} A user-defined function that is called when the `WritableStream` is closed.", 1048 "name": "close", 1049 "type": "Function", 1050 "desc": "A user-defined function that is called when the `WritableStream` is closed.", 1051 "options": [ 1052 { 1053 "textRaw": "Returns: A promise fulfilled with `undefined`.", 1054 "name": "return", 1055 "desc": "A promise fulfilled with `undefined`." 1056 } 1057 ] 1058 }, 1059 { 1060 "textRaw": "`abort` {Function} A user-defined function that is called to abruptly close the `WritableStream`.", 1061 "name": "abort", 1062 "type": "Function", 1063 "desc": "A user-defined function that is called to abruptly close the `WritableStream`.", 1064 "options": [ 1065 { 1066 "textRaw": "`reason` {any}", 1067 "name": "reason", 1068 "type": "any" 1069 }, 1070 { 1071 "textRaw": "Returns: A promise fulfilled with `undefined`.", 1072 "name": "return", 1073 "desc": "A promise fulfilled with `undefined`." 1074 } 1075 ] 1076 }, 1077 { 1078 "textRaw": "`type` {any} The `type` option is reserved for future use and _must_ be undefined.", 1079 "name": "type", 1080 "type": "any", 1081 "desc": "The `type` option is reserved for future use and _must_ be undefined." 1082 } 1083 ] 1084 }, 1085 { 1086 "textRaw": "`strategy` {Object}", 1087 "name": "strategy", 1088 "type": "Object", 1089 "options": [ 1090 { 1091 "textRaw": "`highWaterMark` {number} The maximum internal queue size before backpressure is applied.", 1092 "name": "highWaterMark", 1093 "type": "number", 1094 "desc": "The maximum internal queue size before backpressure is applied." 1095 }, 1096 { 1097 "textRaw": "`size` {Function} A user-defined function used to identify the size of each chunk of data.", 1098 "name": "size", 1099 "type": "Function", 1100 "desc": "A user-defined function used to identify the size of each chunk of data.", 1101 "options": [ 1102 { 1103 "textRaw": "`chunk` {any}", 1104 "name": "chunk", 1105 "type": "any" 1106 }, 1107 { 1108 "textRaw": "Returns: {number}", 1109 "name": "return", 1110 "type": "number" 1111 } 1112 ] 1113 } 1114 ] 1115 } 1116 ] 1117 } 1118 ] 1119 }, 1120 { 1121 "textRaw": "Class: `WritableStreamDefaultWriter`", 1122 "type": "class", 1123 "name": "WritableStreamDefaultWriter", 1124 "meta": { 1125 "added": [ 1126 "v16.5.0" 1127 ], 1128 "changes": [ 1129 { 1130 "version": "v18.0.0", 1131 "pr-url": "https://github.com/nodejs/node/pull/42225", 1132 "description": "This class is now exposed on the global object." 1133 } 1134 ] 1135 }, 1136 "methods": [ 1137 { 1138 "textRaw": "`writableStreamDefaultWriter.abort([reason])`", 1139 "type": "method", 1140 "name": "abort", 1141 "meta": { 1142 "added": [ 1143 "v16.5.0" 1144 ], 1145 "changes": [] 1146 }, 1147 "signatures": [ 1148 { 1149 "return": { 1150 "textRaw": "Returns: A promise fulfilled with `undefined`.", 1151 "name": "return", 1152 "desc": "A promise fulfilled with `undefined`." 1153 }, 1154 "params": [ 1155 { 1156 "textRaw": "`reason` {any}", 1157 "name": "reason", 1158 "type": "any" 1159 } 1160 ] 1161 } 1162 ], 1163 "desc": "<p>Abruptly terminates the <code>WritableStream</code>. All queued writes will be\ncanceled with their associated promises rejected.</p>" 1164 }, 1165 { 1166 "textRaw": "`writableStreamDefaultWriter.close()`", 1167 "type": "method", 1168 "name": "close", 1169 "meta": { 1170 "added": [ 1171 "v16.5.0" 1172 ], 1173 "changes": [] 1174 }, 1175 "signatures": [ 1176 { 1177 "return": { 1178 "textRaw": "Returns: A promise fulfilled with `undefined`.", 1179 "name": "return", 1180 "desc": "A promise fulfilled with `undefined`." 1181 }, 1182 "params": [] 1183 } 1184 ], 1185 "desc": "<p>Closes the <code>WritableStream</code> when no additional writes are expected.</p>" 1186 }, 1187 { 1188 "textRaw": "`writableStreamDefaultWriter.releaseLock()`", 1189 "type": "method", 1190 "name": "releaseLock", 1191 "meta": { 1192 "added": [ 1193 "v16.5.0" 1194 ], 1195 "changes": [] 1196 }, 1197 "signatures": [ 1198 { 1199 "params": [] 1200 } 1201 ], 1202 "desc": "<p>Releases this writer's lock on the underlying <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a>.</p>" 1203 }, 1204 { 1205 "textRaw": "`writableStreamDefaultWriter.write([chunk])`", 1206 "type": "method", 1207 "name": "write", 1208 "meta": { 1209 "added": [ 1210 "v16.5.0" 1211 ], 1212 "changes": [] 1213 }, 1214 "signatures": [ 1215 { 1216 "return": { 1217 "textRaw": "Returns: A promise fulfilled with `undefined`.", 1218 "name": "return", 1219 "desc": "A promise fulfilled with `undefined`." 1220 }, 1221 "params": [ 1222 { 1223 "textRaw": "`chunk`: {any}", 1224 "name": "chunk", 1225 "type": "any" 1226 } 1227 ] 1228 } 1229 ], 1230 "desc": "<p>Appends a new chunk of data to the <a href=\"webstreams.html#class-writablestream\" class=\"type\"><WritableStream></a>'s queue.</p>" 1231 } 1232 ], 1233 "properties": [ 1234 { 1235 "textRaw": "`closed` Type: {Promise} Fulfilled with `undefined` when the associated {WritableStream} is closed or rejected if the stream errors or the writer's lock is released before the stream finishes closing.", 1236 "type": "Promise", 1237 "name": "Type", 1238 "meta": { 1239 "added": [ 1240 "v16.5.0" 1241 ], 1242 "changes": [] 1243 }, 1244 "desc": "Fulfilled with `undefined` when the associated {WritableStream} is closed or rejected if the stream errors or the writer's lock is released before the stream finishes closing." 1245 }, 1246 { 1247 "textRaw": "`desiredSize` Type: {number}", 1248 "type": "number", 1249 "name": "Type", 1250 "meta": { 1251 "added": [ 1252 "v16.5.0" 1253 ], 1254 "changes": [] 1255 }, 1256 "desc": "<p>The amount of data required to fill the <a href=\"webstreams.html#class-writablestream\" class=\"type\"><WritableStream></a>'s queue.</p>" 1257 }, 1258 { 1259 "textRaw": "`ready` Type: {Promise} Fulfilled with `undefined` when the writer is ready to be used.", 1260 "type": "Promise", 1261 "name": "Type", 1262 "meta": { 1263 "added": [ 1264 "v16.5.0" 1265 ], 1266 "changes": [] 1267 }, 1268 "desc": "Fulfilled with `undefined` when the writer is ready to be used." 1269 } 1270 ], 1271 "signatures": [ 1272 { 1273 "params": [ 1274 { 1275 "textRaw": "`stream` {WritableStream}", 1276 "name": "stream", 1277 "type": "WritableStream" 1278 } 1279 ], 1280 "desc": "<p>Creates a new <code>WritableStreamDefaultWriter</code> that is locked to the given\n<code>WritableStream</code>.</p>" 1281 } 1282 ] 1283 }, 1284 { 1285 "textRaw": "Class: `WritableStreamDefaultController`", 1286 "type": "class", 1287 "name": "WritableStreamDefaultController", 1288 "meta": { 1289 "added": [ 1290 "v16.5.0" 1291 ], 1292 "changes": [ 1293 { 1294 "version": "v18.0.0", 1295 "pr-url": "https://github.com/nodejs/node/pull/42225", 1296 "description": "This class is now exposed on the global object." 1297 } 1298 ] 1299 }, 1300 "desc": "<p>The <code>WritableStreamDefaultController</code> manage's the <a href=\"webstreams.html#class-writablestream\" class=\"type\"><WritableStream></a>'s\ninternal state.</p>", 1301 "methods": [ 1302 { 1303 "textRaw": "`writableStreamDefaultController.error([error])`", 1304 "type": "method", 1305 "name": "error", 1306 "meta": { 1307 "added": [ 1308 "v16.5.0" 1309 ], 1310 "changes": [] 1311 }, 1312 "signatures": [ 1313 { 1314 "params": [ 1315 { 1316 "textRaw": "`error` {any}", 1317 "name": "error", 1318 "type": "any" 1319 } 1320 ] 1321 } 1322 ], 1323 "desc": "<p>Called by user-code to signal that an error has occurred while processing\nthe <code>WritableStream</code> data. When called, the <a href=\"webstreams.html#class-writablestream\" class=\"type\"><WritableStream></a> will be aborted,\nwith currently pending writes canceled.</p>" 1324 } 1325 ], 1326 "properties": [ 1327 { 1328 "textRaw": "`signal` Type: {AbortSignal} An `AbortSignal` that can be used to cancel pending write or close operations when a {WritableStream} is aborted.", 1329 "type": "AbortSignal", 1330 "name": "Type", 1331 "desc": "An `AbortSignal` that can be used to cancel pending write or close operations when a {WritableStream} is aborted." 1332 } 1333 ] 1334 }, 1335 { 1336 "textRaw": "Class: `TransformStream`", 1337 "type": "class", 1338 "name": "TransformStream", 1339 "meta": { 1340 "added": [ 1341 "v16.5.0" 1342 ], 1343 "changes": [ 1344 { 1345 "version": "v18.0.0", 1346 "pr-url": "https://github.com/nodejs/node/pull/42225", 1347 "description": "This class is now exposed on the global object." 1348 } 1349 ] 1350 }, 1351 "desc": "<p>A <code>TransformStream</code> consists of a <a href=\"webstreams.html#class-readablestream\" class=\"type\"><ReadableStream></a> and a <a href=\"webstreams.html#class-writablestream\" class=\"type\"><WritableStream></a> that\nare connected such that the data written to the <code>WritableStream</code> is received,\nand potentially transformed, before being pushed into the <code>ReadableStream</code>'s\nqueue.</p>\n<pre><code class=\"language-mjs\">import {\n TransformStream,\n} from 'node:stream/web';\n\nconst transform = new TransformStream({\n transform(chunk, controller) {\n controller.enqueue(chunk.toUpperCase());\n },\n});\n\nawait Promise.all([\n transform.writable.getWriter().write('A'),\n transform.readable.getReader().read(),\n]);\n</code></pre>", 1352 "properties": [ 1353 { 1354 "textRaw": "`readable` Type: {ReadableStream}", 1355 "type": "ReadableStream", 1356 "name": "Type", 1357 "meta": { 1358 "added": [ 1359 "v16.5.0" 1360 ], 1361 "changes": [] 1362 } 1363 }, 1364 { 1365 "textRaw": "`writable` Type: {WritableStream}", 1366 "type": "WritableStream", 1367 "name": "Type", 1368 "meta": { 1369 "added": [ 1370 "v16.5.0" 1371 ], 1372 "changes": [] 1373 } 1374 } 1375 ], 1376 "modules": [ 1377 { 1378 "textRaw": "Transferring with postMessage()", 1379 "name": "transferring_with_postmessage()", 1380 "desc": "<p>A <a href=\"webstreams.html#class-transformstream\" class=\"type\"><TransformStream></a> instance can be transferred using a <a href=\"worker_threads.html#class-messageport\" class=\"type\"><MessagePort></a>.</p>\n<pre><code class=\"language-js\">const stream = new TransformStream();\n\nconst { port1, port2 } = new MessageChannel();\n\nport1.onmessage = ({ data }) => {\n const { writable, readable } = data;\n // ...\n};\n\nport2.postMessage(stream, [stream]);\n</code></pre>", 1381 "type": "module", 1382 "displayName": "Transferring with postMessage()" 1383 } 1384 ], 1385 "signatures": [ 1386 { 1387 "params": [ 1388 { 1389 "textRaw": "`transformer` {Object}", 1390 "name": "transformer", 1391 "type": "Object", 1392 "options": [ 1393 { 1394 "textRaw": "`start` {Function} A user-defined function that is invoked immediately when the `TransformStream` is created.", 1395 "name": "start", 1396 "type": "Function", 1397 "desc": "A user-defined function that is invoked immediately when the `TransformStream` is created.", 1398 "options": [ 1399 { 1400 "textRaw": "`controller` {TransformStreamDefaultController}", 1401 "name": "controller", 1402 "type": "TransformStreamDefaultController" 1403 }, 1404 { 1405 "textRaw": "Returns: `undefined` or a promise fulfilled with `undefined`", 1406 "name": "return", 1407 "desc": "`undefined` or a promise fulfilled with `undefined`" 1408 } 1409 ] 1410 }, 1411 { 1412 "textRaw": "`transform` {Function} A user-defined function that receives, and potentially modifies, a chunk of data written to `transformStream.writable`, before forwarding that on to `transformStream.readable`.", 1413 "name": "transform", 1414 "type": "Function", 1415 "desc": "A user-defined function that receives, and potentially modifies, a chunk of data written to `transformStream.writable`, before forwarding that on to `transformStream.readable`.", 1416 "options": [ 1417 { 1418 "textRaw": "`chunk` {any}", 1419 "name": "chunk", 1420 "type": "any" 1421 }, 1422 { 1423 "textRaw": "`controller` {TransformStreamDefaultController}", 1424 "name": "controller", 1425 "type": "TransformStreamDefaultController" 1426 }, 1427 { 1428 "textRaw": "Returns: A promise fulfilled with `undefined`.", 1429 "name": "return", 1430 "desc": "A promise fulfilled with `undefined`." 1431 } 1432 ] 1433 }, 1434 { 1435 "textRaw": "`flush` {Function} A user-defined function that is called immediately before the writable side of the `TransformStream` is closed, signaling the end of the transformation process.", 1436 "name": "flush", 1437 "type": "Function", 1438 "desc": "A user-defined function that is called immediately before the writable side of the `TransformStream` is closed, signaling the end of the transformation process.", 1439 "options": [ 1440 { 1441 "textRaw": "`controller` {TransformStreamDefaultController}", 1442 "name": "controller", 1443 "type": "TransformStreamDefaultController" 1444 }, 1445 { 1446 "textRaw": "Returns: A promise fulfilled with `undefined`.", 1447 "name": "return", 1448 "desc": "A promise fulfilled with `undefined`." 1449 } 1450 ] 1451 }, 1452 { 1453 "textRaw": "`readableType` {any} the `readableType` option is reserved for future use and _must_ be `undefined`.", 1454 "name": "readableType", 1455 "type": "any", 1456 "desc": "the `readableType` option is reserved for future use and _must_ be `undefined`." 1457 }, 1458 { 1459 "textRaw": "`writableType` {any} the `writableType` option is reserved for future use and _must_ be `undefined`.", 1460 "name": "writableType", 1461 "type": "any", 1462 "desc": "the `writableType` option is reserved for future use and _must_ be `undefined`." 1463 } 1464 ] 1465 }, 1466 { 1467 "textRaw": "`writableStrategy` {Object}", 1468 "name": "writableStrategy", 1469 "type": "Object", 1470 "options": [ 1471 { 1472 "textRaw": "`highWaterMark` {number} The maximum internal queue size before backpressure is applied.", 1473 "name": "highWaterMark", 1474 "type": "number", 1475 "desc": "The maximum internal queue size before backpressure is applied." 1476 }, 1477 { 1478 "textRaw": "`size` {Function} A user-defined function used to identify the size of each chunk of data.", 1479 "name": "size", 1480 "type": "Function", 1481 "desc": "A user-defined function used to identify the size of each chunk of data.", 1482 "options": [ 1483 { 1484 "textRaw": "`chunk` {any}", 1485 "name": "chunk", 1486 "type": "any" 1487 }, 1488 { 1489 "textRaw": "Returns: {number}", 1490 "name": "return", 1491 "type": "number" 1492 } 1493 ] 1494 } 1495 ] 1496 }, 1497 { 1498 "textRaw": "`readableStrategy` {Object}", 1499 "name": "readableStrategy", 1500 "type": "Object", 1501 "options": [ 1502 { 1503 "textRaw": "`highWaterMark` {number} The maximum internal queue size before backpressure is applied.", 1504 "name": "highWaterMark", 1505 "type": "number", 1506 "desc": "The maximum internal queue size before backpressure is applied." 1507 }, 1508 { 1509 "textRaw": "`size` {Function} A user-defined function used to identify the size of each chunk of data.", 1510 "name": "size", 1511 "type": "Function", 1512 "desc": "A user-defined function used to identify the size of each chunk of data.", 1513 "options": [ 1514 { 1515 "textRaw": "`chunk` {any}", 1516 "name": "chunk", 1517 "type": "any" 1518 }, 1519 { 1520 "textRaw": "Returns: {number}", 1521 "name": "return", 1522 "type": "number" 1523 } 1524 ] 1525 } 1526 ] 1527 } 1528 ] 1529 } 1530 ] 1531 }, 1532 { 1533 "textRaw": "Class: `TransformStreamDefaultController`", 1534 "type": "class", 1535 "name": "TransformStreamDefaultController", 1536 "meta": { 1537 "added": [ 1538 "v16.5.0" 1539 ], 1540 "changes": [ 1541 { 1542 "version": "v18.0.0", 1543 "pr-url": "https://github.com/nodejs/node/pull/42225", 1544 "description": "This class is now exposed on the global object." 1545 } 1546 ] 1547 }, 1548 "desc": "<p>The <code>TransformStreamDefaultController</code> manages the internal state\nof the <code>TransformStream</code>.</p>", 1549 "properties": [ 1550 { 1551 "textRaw": "`desiredSize` Type: {number}", 1552 "type": "number", 1553 "name": "Type", 1554 "meta": { 1555 "added": [ 1556 "v16.5.0" 1557 ], 1558 "changes": [] 1559 }, 1560 "desc": "<p>The amount of data required to fill the readable side's queue.</p>" 1561 } 1562 ], 1563 "methods": [ 1564 { 1565 "textRaw": "`transformStreamDefaultController.enqueue([chunk])`", 1566 "type": "method", 1567 "name": "enqueue", 1568 "meta": { 1569 "added": [ 1570 "v16.5.0" 1571 ], 1572 "changes": [] 1573 }, 1574 "signatures": [ 1575 { 1576 "params": [ 1577 { 1578 "textRaw": "`chunk` {any}", 1579 "name": "chunk", 1580 "type": "any" 1581 } 1582 ] 1583 } 1584 ], 1585 "desc": "<p>Appends a chunk of data to the readable side's queue.</p>" 1586 }, 1587 { 1588 "textRaw": "`transformStreamDefaultController.error([reason])`", 1589 "type": "method", 1590 "name": "error", 1591 "meta": { 1592 "added": [ 1593 "v16.5.0" 1594 ], 1595 "changes": [] 1596 }, 1597 "signatures": [ 1598 { 1599 "params": [ 1600 { 1601 "textRaw": "`reason` {any}", 1602 "name": "reason", 1603 "type": "any" 1604 } 1605 ] 1606 } 1607 ], 1608 "desc": "<p>Signals to both the readable and writable side that an error has occurred\nwhile processing the transform data, causing both sides to be abruptly\nclosed.</p>" 1609 }, 1610 { 1611 "textRaw": "`transformStreamDefaultController.terminate()`", 1612 "type": "method", 1613 "name": "terminate", 1614 "meta": { 1615 "added": [ 1616 "v16.5.0" 1617 ], 1618 "changes": [] 1619 }, 1620 "signatures": [ 1621 { 1622 "params": [] 1623 } 1624 ], 1625 "desc": "<p>Closes the readable side of the transport and causes the writable side\nto be abruptly closed with an error.</p>" 1626 } 1627 ] 1628 }, 1629 { 1630 "textRaw": "Class: `ByteLengthQueuingStrategy`", 1631 "type": "class", 1632 "name": "ByteLengthQueuingStrategy", 1633 "meta": { 1634 "added": [ 1635 "v16.5.0" 1636 ], 1637 "changes": [ 1638 { 1639 "version": "v18.0.0", 1640 "pr-url": "https://github.com/nodejs/node/pull/42225", 1641 "description": "This class is now exposed on the global object." 1642 } 1643 ] 1644 }, 1645 "properties": [ 1646 { 1647 "textRaw": "`highWaterMark` Type: {number}", 1648 "type": "number", 1649 "name": "Type", 1650 "meta": { 1651 "added": [ 1652 "v16.5.0" 1653 ], 1654 "changes": [] 1655 } 1656 }, 1657 { 1658 "textRaw": "`size` Type: {Function}", 1659 "type": "Function", 1660 "name": "Type", 1661 "meta": { 1662 "added": [ 1663 "v16.5.0" 1664 ], 1665 "changes": [] 1666 }, 1667 "options": [ 1668 { 1669 "textRaw": "`chunk` {any}", 1670 "name": "chunk", 1671 "type": "any" 1672 }, 1673 { 1674 "textRaw": "Returns: {number}", 1675 "name": "return", 1676 "type": "number" 1677 } 1678 ] 1679 } 1680 ], 1681 "signatures": [ 1682 { 1683 "params": [ 1684 { 1685 "textRaw": "`init` {Object}", 1686 "name": "init", 1687 "type": "Object", 1688 "options": [ 1689 { 1690 "textRaw": "`highWaterMark` {number}", 1691 "name": "highWaterMark", 1692 "type": "number" 1693 } 1694 ] 1695 } 1696 ] 1697 } 1698 ] 1699 }, 1700 { 1701 "textRaw": "Class: `CountQueuingStrategy`", 1702 "type": "class", 1703 "name": "CountQueuingStrategy", 1704 "meta": { 1705 "added": [ 1706 "v16.5.0" 1707 ], 1708 "changes": [ 1709 { 1710 "version": "v18.0.0", 1711 "pr-url": "https://github.com/nodejs/node/pull/42225", 1712 "description": "This class is now exposed on the global object." 1713 } 1714 ] 1715 }, 1716 "properties": [ 1717 { 1718 "textRaw": "`highWaterMark` Type: {number}", 1719 "type": "number", 1720 "name": "Type", 1721 "meta": { 1722 "added": [ 1723 "v16.5.0" 1724 ], 1725 "changes": [] 1726 } 1727 }, 1728 { 1729 "textRaw": "`size` Type: {Function}", 1730 "type": "Function", 1731 "name": "Type", 1732 "meta": { 1733 "added": [ 1734 "v16.5.0" 1735 ], 1736 "changes": [] 1737 }, 1738 "options": [ 1739 { 1740 "textRaw": "`chunk` {any}", 1741 "name": "chunk", 1742 "type": "any" 1743 }, 1744 { 1745 "textRaw": "Returns: {number}", 1746 "name": "return", 1747 "type": "number" 1748 } 1749 ] 1750 } 1751 ], 1752 "signatures": [ 1753 { 1754 "params": [ 1755 { 1756 "textRaw": "`init` {Object}", 1757 "name": "init", 1758 "type": "Object", 1759 "options": [ 1760 { 1761 "textRaw": "`highWaterMark` {number}", 1762 "name": "highWaterMark", 1763 "type": "number" 1764 } 1765 ] 1766 } 1767 ] 1768 } 1769 ] 1770 }, 1771 { 1772 "textRaw": "Class: `TextEncoderStream`", 1773 "type": "class", 1774 "name": "TextEncoderStream", 1775 "meta": { 1776 "added": [ 1777 "v16.6.0" 1778 ], 1779 "changes": [ 1780 { 1781 "version": "v18.0.0", 1782 "pr-url": "https://github.com/nodejs/node/pull/42225", 1783 "description": "This class is now exposed on the global object." 1784 } 1785 ] 1786 }, 1787 "properties": [ 1788 { 1789 "textRaw": "`encoding` Type: {string}", 1790 "type": "string", 1791 "name": "Type", 1792 "meta": { 1793 "added": [ 1794 "v16.6.0" 1795 ], 1796 "changes": [] 1797 }, 1798 "desc": "<p>The encoding supported by the <code>TextEncoderStream</code> instance.</p>" 1799 }, 1800 { 1801 "textRaw": "`readable` Type: {ReadableStream}", 1802 "type": "ReadableStream", 1803 "name": "Type", 1804 "meta": { 1805 "added": [ 1806 "v16.6.0" 1807 ], 1808 "changes": [] 1809 } 1810 }, 1811 { 1812 "textRaw": "`writable` Type: {WritableStream}", 1813 "type": "WritableStream", 1814 "name": "Type", 1815 "meta": { 1816 "added": [ 1817 "v16.6.0" 1818 ], 1819 "changes": [] 1820 } 1821 } 1822 ], 1823 "signatures": [ 1824 { 1825 "params": [], 1826 "desc": "<p>Creates a new <code>TextEncoderStream</code> instance.</p>" 1827 } 1828 ] 1829 }, 1830 { 1831 "textRaw": "Class: `TextDecoderStream`", 1832 "type": "class", 1833 "name": "TextDecoderStream", 1834 "meta": { 1835 "added": [ 1836 "v16.6.0" 1837 ], 1838 "changes": [ 1839 { 1840 "version": "v18.0.0", 1841 "pr-url": "https://github.com/nodejs/node/pull/42225", 1842 "description": "This class is now exposed on the global object." 1843 } 1844 ] 1845 }, 1846 "properties": [ 1847 { 1848 "textRaw": "`encoding` Type: {string}", 1849 "type": "string", 1850 "name": "Type", 1851 "meta": { 1852 "added": [ 1853 "v16.6.0" 1854 ], 1855 "changes": [] 1856 }, 1857 "desc": "<p>The encoding supported by the <code>TextDecoderStream</code> instance.</p>" 1858 }, 1859 { 1860 "textRaw": "`fatal` Type: {boolean}", 1861 "type": "boolean", 1862 "name": "Type", 1863 "meta": { 1864 "added": [ 1865 "v16.6.0" 1866 ], 1867 "changes": [] 1868 }, 1869 "desc": "<p>The value will be <code>true</code> if decoding errors result in a <code>TypeError</code> being\nthrown.</p>" 1870 }, 1871 { 1872 "textRaw": "`ignoreBOM` Type: {boolean}", 1873 "type": "boolean", 1874 "name": "Type", 1875 "meta": { 1876 "added": [ 1877 "v16.6.0" 1878 ], 1879 "changes": [] 1880 }, 1881 "desc": "<p>The value will be <code>true</code> if the decoding result will include the byte order\nmark.</p>" 1882 }, 1883 { 1884 "textRaw": "`readable` Type: {ReadableStream}", 1885 "type": "ReadableStream", 1886 "name": "Type", 1887 "meta": { 1888 "added": [ 1889 "v16.6.0" 1890 ], 1891 "changes": [] 1892 } 1893 }, 1894 { 1895 "textRaw": "`writable` Type: {WritableStream}", 1896 "type": "WritableStream", 1897 "name": "Type", 1898 "meta": { 1899 "added": [ 1900 "v16.6.0" 1901 ], 1902 "changes": [] 1903 } 1904 } 1905 ], 1906 "signatures": [ 1907 { 1908 "params": [ 1909 { 1910 "textRaw": "`encoding` {string} Identifies the `encoding` that this `TextDecoder` instance supports. **Default:** `'utf-8'`.", 1911 "name": "encoding", 1912 "type": "string", 1913 "default": "`'utf-8'`", 1914 "desc": "Identifies the `encoding` that this `TextDecoder` instance supports." 1915 }, 1916 { 1917 "textRaw": "`options` {Object}", 1918 "name": "options", 1919 "type": "Object", 1920 "options": [ 1921 { 1922 "textRaw": "`fatal` {boolean} `true` if decoding failures are fatal.", 1923 "name": "fatal", 1924 "type": "boolean", 1925 "desc": "`true` if decoding failures are fatal." 1926 }, 1927 { 1928 "textRaw": "`ignoreBOM` {boolean} When `true`, the `TextDecoderStream` will include the byte order mark in the decoded result. When `false`, the byte order mark will be removed from the output. This option is only used when `encoding` is `'utf-8'`, `'utf-16be'`, or `'utf-16le'`. **Default:** `false`.", 1929 "name": "ignoreBOM", 1930 "type": "boolean", 1931 "default": "`false`", 1932 "desc": "When `true`, the `TextDecoderStream` will include the byte order mark in the decoded result. When `false`, the byte order mark will be removed from the output. This option is only used when `encoding` is `'utf-8'`, `'utf-16be'`, or `'utf-16le'`." 1933 } 1934 ] 1935 } 1936 ], 1937 "desc": "<p>Creates a new <code>TextDecoderStream</code> instance.</p>" 1938 } 1939 ] 1940 }, 1941 { 1942 "textRaw": "Class: `CompressionStream`", 1943 "type": "class", 1944 "name": "CompressionStream", 1945 "meta": { 1946 "added": [ 1947 "v17.0.0" 1948 ], 1949 "changes": [ 1950 { 1951 "version": "v18.0.0", 1952 "pr-url": "https://github.com/nodejs/node/pull/42225", 1953 "description": "This class is now exposed on the global object." 1954 } 1955 ] 1956 }, 1957 "properties": [ 1958 { 1959 "textRaw": "`readable` Type: {ReadableStream}", 1960 "type": "ReadableStream", 1961 "name": "Type", 1962 "meta": { 1963 "added": [ 1964 "v17.0.0" 1965 ], 1966 "changes": [] 1967 } 1968 }, 1969 { 1970 "textRaw": "`writable` Type: {WritableStream}", 1971 "type": "WritableStream", 1972 "name": "Type", 1973 "meta": { 1974 "added": [ 1975 "v17.0.0" 1976 ], 1977 "changes": [] 1978 } 1979 } 1980 ], 1981 "signatures": [ 1982 { 1983 "params": [ 1984 { 1985 "textRaw": "`format` {string} One of either `'deflate'` or `'gzip'`.", 1986 "name": "format", 1987 "type": "string", 1988 "desc": "One of either `'deflate'` or `'gzip'`." 1989 } 1990 ] 1991 } 1992 ] 1993 }, 1994 { 1995 "textRaw": "Class: `DecompressionStream`", 1996 "type": "class", 1997 "name": "DecompressionStream", 1998 "meta": { 1999 "added": [ 2000 "v17.0.0" 2001 ], 2002 "changes": [ 2003 { 2004 "version": "v18.0.0", 2005 "pr-url": "https://github.com/nodejs/node/pull/42225", 2006 "description": "This class is now exposed on the global object." 2007 } 2008 ] 2009 }, 2010 "properties": [ 2011 { 2012 "textRaw": "`readable` Type: {ReadableStream}", 2013 "type": "ReadableStream", 2014 "name": "Type", 2015 "meta": { 2016 "added": [ 2017 "v17.0.0" 2018 ], 2019 "changes": [] 2020 } 2021 }, 2022 { 2023 "textRaw": "`writable` Type: {WritableStream}", 2024 "type": "WritableStream", 2025 "name": "Type", 2026 "meta": { 2027 "added": [ 2028 "v17.0.0" 2029 ], 2030 "changes": [] 2031 } 2032 } 2033 ], 2034 "signatures": [ 2035 { 2036 "params": [ 2037 { 2038 "textRaw": "`format` {string} One of either `'deflate'` or `'gzip'`.", 2039 "name": "format", 2040 "type": "string", 2041 "desc": "One of either `'deflate'` or `'gzip'`." 2042 } 2043 ] 2044 } 2045 ] 2046 } 2047 ], 2048 "modules": [ 2049 { 2050 "textRaw": "Utility Consumers", 2051 "name": "utility_consumers", 2052 "meta": { 2053 "added": [ 2054 "v16.7.0" 2055 ], 2056 "changes": [] 2057 }, 2058 "desc": "<p>The utility consumer functions provide common options for consuming\nstreams.</p>\n<p>They are accessed using:</p>\n<pre><code class=\"language-mjs\">import {\n arrayBuffer,\n blob,\n buffer,\n json,\n text,\n} from 'node:stream/consumers';\n</code></pre>\n<pre><code class=\"language-cjs\">const {\n arrayBuffer,\n blob,\n buffer,\n json,\n text,\n} = require('node:stream/consumers');\n</code></pre>", 2059 "methods": [ 2060 { 2061 "textRaw": "`streamConsumers.arrayBuffer(stream)`", 2062 "type": "method", 2063 "name": "arrayBuffer", 2064 "meta": { 2065 "added": [ 2066 "v16.7.0" 2067 ], 2068 "changes": [] 2069 }, 2070 "signatures": [ 2071 { 2072 "return": { 2073 "textRaw": "Returns: {Promise} Fulfills with an `ArrayBuffer` containing the full contents of the stream.", 2074 "name": "return", 2075 "type": "Promise", 2076 "desc": "Fulfills with an `ArrayBuffer` containing the full contents of the stream." 2077 }, 2078 "params": [ 2079 { 2080 "textRaw": "`stream` {ReadableStream|stream.Readable|AsyncIterator}", 2081 "name": "stream", 2082 "type": "ReadableStream|stream.Readable|AsyncIterator" 2083 } 2084 ] 2085 } 2086 ], 2087 "desc": "<pre><code class=\"language-mjs\">import { arrayBuffer } from 'node:stream/consumers';\nimport { Readable } from 'node:stream';\nimport { TextEncoder } from 'node:util';\n\nconst encoder = new TextEncoder();\nconst dataArray = encoder.encode('hello world from consumers!');\n\nconst readable = Readable.from(dataArray);\nconst data = await arrayBuffer(readable);\nconsole.log(`from readable: ${data.byteLength}`);\n</code></pre>\n<pre><code class=\"language-cjs\">const { arrayBuffer } = require('node:stream/consumers');\nconst { Readable } = require('node:stream');\nconst { TextEncoder } = require('node:util');\n\nconst encoder = new TextEncoder();\nconst dataArray = encoder.encode('hello world from consumers!');\nconst readable = Readable.from(dataArray);\narrayBuffer(readable).then((data) => {\n console.log(`from readable: ${data.byteLength}`);\n});\n</code></pre>" 2088 }, 2089 { 2090 "textRaw": "`streamConsumers.blob(stream)`", 2091 "type": "method", 2092 "name": "blob", 2093 "meta": { 2094 "added": [ 2095 "v16.7.0" 2096 ], 2097 "changes": [] 2098 }, 2099 "signatures": [ 2100 { 2101 "return": { 2102 "textRaw": "Returns: {Promise} Fulfills with a {Blob} containing the full contents of the stream.", 2103 "name": "return", 2104 "type": "Promise", 2105 "desc": "Fulfills with a {Blob} containing the full contents of the stream." 2106 }, 2107 "params": [ 2108 { 2109 "textRaw": "`stream` {ReadableStream|stream.Readable|AsyncIterator}", 2110 "name": "stream", 2111 "type": "ReadableStream|stream.Readable|AsyncIterator" 2112 } 2113 ] 2114 } 2115 ], 2116 "desc": "<pre><code class=\"language-mjs\">import { blob } from 'node:stream/consumers';\n\nconst dataBlob = new Blob(['hello world from consumers!']);\n\nconst readable = dataBlob.stream();\nconst data = await blob(readable);\nconsole.log(`from readable: ${data.size}`);\n</code></pre>\n<pre><code class=\"language-cjs\">const { blob } = require('node:stream/consumers');\n\nconst dataBlob = new Blob(['hello world from consumers!']);\n\nconst readable = dataBlob.stream();\nblob(readable).then((data) => {\n console.log(`from readable: ${data.size}`);\n});\n</code></pre>" 2117 }, 2118 { 2119 "textRaw": "`streamConsumers.buffer(stream)`", 2120 "type": "method", 2121 "name": "buffer", 2122 "meta": { 2123 "added": [ 2124 "v16.7.0" 2125 ], 2126 "changes": [] 2127 }, 2128 "signatures": [ 2129 { 2130 "return": { 2131 "textRaw": "Returns: {Promise} Fulfills with a {Buffer} containing the full contents of the stream.", 2132 "name": "return", 2133 "type": "Promise", 2134 "desc": "Fulfills with a {Buffer} containing the full contents of the stream." 2135 }, 2136 "params": [ 2137 { 2138 "textRaw": "`stream` {ReadableStream|stream.Readable|AsyncIterator}", 2139 "name": "stream", 2140 "type": "ReadableStream|stream.Readable|AsyncIterator" 2141 } 2142 ] 2143 } 2144 ], 2145 "desc": "<pre><code class=\"language-mjs\">import { buffer } from 'node:stream/consumers';\nimport { Readable } from 'node:stream';\nimport { Buffer } from 'node:buffer';\n\nconst dataBuffer = Buffer.from('hello world from consumers!');\n\nconst readable = Readable.from(dataBuffer);\nconst data = await buffer(readable);\nconsole.log(`from readable: ${data.length}`);\n</code></pre>\n<pre><code class=\"language-cjs\">const { buffer } = require('node:stream/consumers');\nconst { Readable } = require('node:stream');\nconst { Buffer } = require('node:buffer');\n\nconst dataBuffer = Buffer.from('hello world from consumers!');\n\nconst readable = Readable.from(dataBuffer);\nbuffer(readable).then((data) => {\n console.log(`from readable: ${data.length}`);\n});\n</code></pre>" 2146 }, 2147 { 2148 "textRaw": "`streamConsumers.json(stream)`", 2149 "type": "method", 2150 "name": "json", 2151 "meta": { 2152 "added": [ 2153 "v16.7.0" 2154 ], 2155 "changes": [] 2156 }, 2157 "signatures": [ 2158 { 2159 "return": { 2160 "textRaw": "Returns: {Promise} Fulfills with the contents of the stream parsed as a UTF-8 encoded string that is then passed through `JSON.parse()`.", 2161 "name": "return", 2162 "type": "Promise", 2163 "desc": "Fulfills with the contents of the stream parsed as a UTF-8 encoded string that is then passed through `JSON.parse()`." 2164 }, 2165 "params": [ 2166 { 2167 "textRaw": "`stream` {ReadableStream|stream.Readable|AsyncIterator}", 2168 "name": "stream", 2169 "type": "ReadableStream|stream.Readable|AsyncIterator" 2170 } 2171 ] 2172 } 2173 ], 2174 "desc": "<pre><code class=\"language-mjs\">import { json } from 'node:stream/consumers';\nimport { Readable } from 'node:stream';\n\nconst items = Array.from(\n {\n length: 100,\n },\n () => ({\n message: 'hello world from consumers!',\n }),\n);\n\nconst readable = Readable.from(JSON.stringify(items));\nconst data = await json(readable);\nconsole.log(`from readable: ${data.length}`);\n</code></pre>\n<pre><code class=\"language-cjs\">const { json } = require('node:stream/consumers');\nconst { Readable } = require('node:stream');\n\nconst items = Array.from(\n {\n length: 100,\n },\n () => ({\n message: 'hello world from consumers!',\n }),\n);\n\nconst readable = Readable.from(JSON.stringify(items));\njson(readable).then((data) => {\n console.log(`from readable: ${data.length}`);\n});\n</code></pre>" 2175 }, 2176 { 2177 "textRaw": "`streamConsumers.text(stream)`", 2178 "type": "method", 2179 "name": "text", 2180 "meta": { 2181 "added": [ 2182 "v16.7.0" 2183 ], 2184 "changes": [] 2185 }, 2186 "signatures": [ 2187 { 2188 "return": { 2189 "textRaw": "Returns: {Promise} Fulfills with the contents of the stream parsed as a UTF-8 encoded string.", 2190 "name": "return", 2191 "type": "Promise", 2192 "desc": "Fulfills with the contents of the stream parsed as a UTF-8 encoded string." 2193 }, 2194 "params": [ 2195 { 2196 "textRaw": "`stream` {ReadableStream|stream.Readable|AsyncIterator}", 2197 "name": "stream", 2198 "type": "ReadableStream|stream.Readable|AsyncIterator" 2199 } 2200 ] 2201 } 2202 ], 2203 "desc": "<pre><code class=\"language-mjs\">import { text } from 'node:stream/consumers';\nimport { Readable } from 'node:stream';\n\nconst readable = Readable.from('Hello world from consumers!');\nconst data = await text(readable);\nconsole.log(`from readable: ${data.length}`);\n</code></pre>\n<pre><code class=\"language-cjs\">const { text } = require('node:stream/consumers');\nconst { Readable } = require('node:stream');\n\nconst readable = Readable.from('Hello world from consumers!');\ntext(readable).then((data) => {\n console.log(`from readable: ${data.length}`);\n});\n</code></pre>" 2204 } 2205 ], 2206 "type": "module", 2207 "displayName": "Utility Consumers" 2208 } 2209 ], 2210 "type": "module", 2211 "displayName": "API" 2212 } 2213 ], 2214 "type": "module", 2215 "displayName": "Web Streams API" 2216 } 2217 ] 2218}