{"$schema":"https://doc-kit.nodejs.org/schemas/api-doc/1.0.0.json","id":"stream_iter","path":"/stream_iter","type":"module","module":"stream_iter","title":"Iterable Streams","introducedIn":"v25.9.0","sourceLink":{"path":"lib/stream/iter.js","url":"https://github.com/nodejs/node/blob/HEAD/lib/stream/iter.js"},"stability":{"index":"1","description":"Experimental – Enable this API with the [`--experimental-stream-iter`](cli.html#--experimental-stream-iter) CLI flag."},"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `node:stream/iter` module provides a streaming API built on iterables\nrather than the event-driven `Readable`/`Writable`/`Transform` class hierarchy,\nor the Web Streams `ReadableStream`/`WritableStream`/`TransformStream` interfaces.\n\nStreams are represented as {AsyncIterable} (async) or {Iterable} (sync). There\nare no base classes to extend -- any\nobject implementing the iterable protocol can participate. Transforms are plain\nfunctions or objects with a `transform` method.\n\nData flows in **batches** ({Uint8Array[]} per iteration) to amortize the cost\nof async operations.\n\n```mjs\nimport { from, pull, text } from 'node:stream/iter';\nimport { compressGzip, decompressGzip } from 'node:zlib/iter';\n\n// Compress and decompress a string\nconst compressed = pull(from('Hello, world!'), compressGzip());\nconst result = await text(pull(compressed, decompressGzip()));\nconsole.log(result); // 'Hello, world!'\n```\n\n```cjs\nconst { from, pull, text } = require('node:stream/iter');\nconst { compressGzip, decompressGzip } = require('node:zlib/iter');\n\nasync function run() {\n  // Compress and decompress a string\n  const compressed = pull(from('Hello, world!'), compressGzip());\n  const result = await text(pull(compressed, decompressGzip()));\n  console.log(result); // 'Hello, world!'\n}\n\nrun().catch(console.error);\n```\n\n```mjs\nimport { open } from 'node:fs/promises';\nimport { text, pipeTo } from 'node:stream/iter';\nimport { compressGzip, decompressGzip } from 'node:zlib/iter';\n\n// Read a file, compress, write to another file\nconst src = await open('input.txt', 'r');\nconst dst = await open('output.gz', 'w');\nawait pipeTo(src.pull(), compressGzip(), dst.writer({ autoClose: true }));\nawait src.close();\n\n// Read it back\nconst gz = await open('output.gz', 'r');\nconsole.log(await text(gz.pull(decompressGzip(), { autoClose: true })));\n```\n\n```cjs\nconst { open } = require('node:fs/promises');\nconst { text, pipeTo } = require('node:stream/iter');\nconst { compressGzip, decompressGzip } = require('node:zlib/iter');\n\nasync function run() {\n  // Read a file, compress, write to another file\n  const src = await open('input.txt', 'r');\n  const dst = await open('output.gz', 'w');\n  await pipeTo(src.pull(), compressGzip(), dst.writer({ autoClose: true }));\n  await src.close();\n\n  // Read it back\n  const gz = await open('output.gz', 'r');\n  console.log(await text(gz.pull(decompressGzip(), { autoClose: true })));\n}\n\nrun().catch(console.error);\n```","summary":"The `node:stream/iter` module provides a streaming API built on iterables rather than the event-driven `Readable`/`Writable`/`Transform` class hierarchy, or the Web Streams `ReadableStream`/`WritableStream`/`TransformStream` interfaces.","examples":[{"language":"mjs","displayName":null,"code":"import { from, pull, text } from 'node:stream/iter';\nimport { compressGzip, decompressGzip } from 'node:zlib/iter';\n\n// Compress and decompress a string\nconst compressed = pull(from('Hello, world!'), compressGzip());\nconst result = await text(pull(compressed, decompressGzip()));\nconsole.log(result); // 'Hello, world!'"},{"language":"cjs","displayName":null,"code":"const { from, pull, text } = require('node:stream/iter');\nconst { compressGzip, decompressGzip } = require('node:zlib/iter');\n\nasync function run() {\n  // Compress and decompress a string\n  const compressed = pull(from('Hello, world!'), compressGzip());\n  const result = await text(pull(compressed, decompressGzip()));\n  console.log(result); // 'Hello, world!'\n}\n\nrun().catch(console.error);"},{"language":"mjs","displayName":null,"code":"import { open } from 'node:fs/promises';\nimport { text, pipeTo } from 'node:stream/iter';\nimport { compressGzip, decompressGzip } from 'node:zlib/iter';\n\n// Read a file, compress, write to another file\nconst src = await open('input.txt', 'r');\nconst dst = await open('output.gz', 'w');\nawait pipeTo(src.pull(), compressGzip(), dst.writer({ autoClose: true }));\nawait src.close();\n\n// Read it back\nconst gz = await open('output.gz', 'r');\nconsole.log(await text(gz.pull(decompressGzip(), { autoClose: true })));"},{"language":"cjs","displayName":null,"code":"const { open } = require('node:fs/promises');\nconst { text, pipeTo } = require('node:stream/iter');\nconst { compressGzip, decompressGzip } = require('node:zlib/iter');\n\nasync function run() {\n  // Read a file, compress, write to another file\n  const src = await open('input.txt', 'r');\n  const dst = await open('output.gz', 'w');\n  await pipeTo(src.pull(), compressGzip(), dst.writer({ autoClose: true }));\n  await src.close();\n\n  // Read it back\n  const gz = await open('output.gz', 'r');\n  console.log(await text(gz.pull(decompressGzip(), { autoClose: true })));\n}\n\nrun().catch(console.error);"}],"children":[{"kind":"section","id":"concepts","name":"Concepts","title":"Concepts","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"byte-streams","name":"Byte streams","title":"Byte streams","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"All data in this API is represented as {Uint8Array} bytes. Strings\nare automatically UTF-8 encoded when passed to `from()`, `push()`, or\n`pipeTo()`. This removes ambiguity around encodings and enables zero-copy\ntransfers between streams and native code.","summary":"All data in this API is represented as {Uint8Array} bytes. Strings are automatically UTF-8 encoded when passed to `from()`, `push()`, or `pipeTo()`. This removes ambiguity around encodings and enables zero-copy transfers between streams and native code.","examples":[],"children":[]},{"kind":"section","id":"batching","name":"Batching","title":"Batching","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Each iteration yields a **batch** -- an {Array} of {Uint8Array} chunks\n({Uint8Array[]}). Batching amortizes the cost of `await` and {Promise} creation\nacross multiple chunks. A consumer that processes one chunk at a time can\nsimply iterate the inner array:\n\n```mjs\nfor await (const batch of source) {\n  for (const chunk of batch) {\n    handle(chunk);\n  }\n}\n```\n\n```cjs\nasync function run() {\n  for await (const batch of source) {\n    for (const chunk of batch) {\n      handle(chunk);\n    }\n  }\n}\n```","summary":"Each iteration yields a **batch** -- an {Array} of {Uint8Array} chunks ({Uint8Array[]}). Batching amortizes the cost of `await` and {Promise} creation across multiple chunks. A consumer that processes one chunk at a time can simply iterate the inner array:","examples":[{"language":"mjs","displayName":null,"code":"for await (const batch of source) {\n  for (const chunk of batch) {\n    handle(chunk);\n  }\n}"},{"language":"cjs","displayName":null,"code":"async function run() {\n  for await (const batch of source) {\n    for (const chunk of batch) {\n      handle(chunk);\n    }\n  }\n}"}],"children":[]},{"kind":"section","id":"transforms","name":"Transforms","title":"Transforms","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Transforms come in two forms:\n\n* **Stateless** -- a function `(chunks, options) => result` called once per\n  batch. Receives `Uint8Array[]` (or `null` as the flush signal) and an\n  `options` object. Returns {Uint8Array[] | null | Iterable}.\n\n* **Stateful** -- an object `{ transform(source, options) }` where `transform`\n  is a generator (sync or async) that receives the entire upstream iterable\n  and an `options` object, and yields output. This form is used for\n  compression, encryption, and any transform that needs to buffer across\n  batches.\n\nBoth forms receive an `options` parameter with the following property:\n\n* `options.signal` {AbortSignal} An AbortSignal that fires when the pipeline\n  is cancelled, encounters an error, or the consumer stops reading. Transforms\n  can check `signal.aborted` or listen for the `'abort'` event to perform\n  early cleanup.\n\nThe flush signal (`null`) is sent after the source ends, giving transforms\na chance to emit trailing data (e.g., compression footers).\n\n```js\n// Stateless: uppercase transform\nconst upper = (chunks) => {\n  if (chunks === null) return null; // flush\n  return chunks.map((c) => new TextEncoder().encode(\n    new TextDecoder().decode(c).toUpperCase(),\n  ));\n};\n\n// Stateful: line splitter\nconst lines = {\n  transform: async function*(source) {\n    let partial = '';\n    for await (const chunks of source) {\n      if (chunks === null) {\n        if (partial) yield [new TextEncoder().encode(partial)];\n        continue;\n      }\n      for (const chunk of chunks) {\n        const str = partial + new TextDecoder().decode(chunk);\n        const parts = str.split('\\n');\n        partial = parts.pop();\n        for (const line of parts) {\n          yield [new TextEncoder().encode(`${line}\\n`)];\n        }\n      }\n    }\n  },\n};\n```","summary":"Transforms come in two forms:","examples":[{"language":"js","displayName":null,"code":"// Stateless: uppercase transform\nconst upper = (chunks) => {\n  if (chunks === null) return null; // flush\n  return chunks.map((c) => new TextEncoder().encode(\n    new TextDecoder().decode(c).toUpperCase(),\n  ));\n};\n\n// Stateful: line splitter\nconst lines = {\n  transform: async function*(source) {\n    let partial = '';\n    for await (const chunks of source) {\n      if (chunks === null) {\n        if (partial) yield [new TextEncoder().encode(partial)];\n        continue;\n      }\n      for (const chunk of chunks) {\n        const str = partial + new TextDecoder().decode(chunk);\n        const parts = str.split('\\n');\n        partial = parts.pop();\n        for (const line of parts) {\n          yield [new TextEncoder().encode(`${line}\\n`)];\n        }\n      }\n    }\n  },\n};"}],"children":[]},{"kind":"section","id":"pull-vs-push","name":"Pull vs. push","title":"Pull vs. push","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The API supports two models:\n\n* **Pull** -- data flows on demand. `pull()` and `pullSync()` create lazy\n  pipelines that only read from the source when the consumer iterates.\n\n* **Push** -- data is written explicitly. `push()` creates a writer/readable\n  pair with backpressure. The writer pushes data in; the readable is consumed\n  as an async iterable.","summary":"The API supports two models:","examples":[],"children":[]},{"kind":"section","id":"backpressure","name":"Backpressure","title":"Backpressure","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Pull streams have natural backpressure -- the consumer drives the pace, so\nthe source is never read faster than the consumer can process. Push streams\nneed explicit backpressure because the producer and consumer run\nindependently. The `budget` and `backpressure` options on `push()`,\n`broadcast()`, and `share()` control how this works.","summary":"Pull streams have natural backpressure -- the consumer drives the pace, so the source is never read faster than the consumer can process. Push streams need explicit backpressure because the producer and consumer run independently. The `budget` and `backpressure` options on `push()`, `broadcast()`, and `share()` control how this works.","examples":[],"children":[{"kind":"section","id":"the-two-buffer-model","name":"The two-buffer model","title":"The two-buffer model","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Push streams use a two-part buffering system. Think of it like a bucket\n(buffer) being filled through a hose (pending writes), with a float valve\nthat closes when the bucket is full:\n\n```text\n                          budget (e.g., 16384)\n                                 |\n    Producer                     v\n       |                    +---------+\n       v                    |         |\n  [ write() ] ----+    +--->| buffer  |---> Consumer pulls\n  [ write() ]     |    |    | (bucket)|     for await (...)\n  [ write() ]     v    |    +---------+\n              +--------+         ^\n              | pending|         |\n              | writes |    float valve\n              | (hose) |    (backpressure)\n              +--------+\n                   ^\n                   |\n          'strict' mode limits this too!\n```\n\n* **Buffer (the bucket)** -- data ready for the consumer, capped at\n  `budget` bytes. When the consumer pulls, it drains all buffered data\n  at once into a single batch.\n\n* **Pending writes (the hose)** -- writes waiting for buffer space. After\n  the consumer drains, pending writes are promoted into the now-empty\n  buffer and their promises settle.\n\nHow each policy uses these buffers:\n\n| Policy          | Buffer limit | Pending writes limit |\n| --------------- | ------------ | -------------------- |\n| `'strict'`      | `budget`     | 1                    |\n| `'unbounded'`   | `budget`     | Unbounded            |\n| `'drop-oldest'` | `budget`     | N/A (never waits)    |\n| `'drop-newest'` | `budget`     | N/A (never waits)    |","summary":"Push streams use a two-part buffering system. Think of it like a bucket (buffer) being filled through a hose (pending writes), with a float valve that closes when the bucket is full:","examples":[{"language":"text","displayName":null,"code":"                          budget (e.g., 16384)\n                                 |\n    Producer                     v\n       |                    +---------+\n       v                    |         |\n  [ write() ] ----+    +--->| buffer  |---> Consumer pulls\n  [ write() ]     |    |    | (bucket)|     for await (...)\n  [ write() ]     v    |    +---------+\n              +--------+         ^\n              | pending|         |\n              | writes |    float valve\n              | (hose) |    (backpressure)\n              +--------+\n                   ^\n                   |\n          'strict' mode limits this too!"}],"children":[]},{"kind":"section","id":"strict-default","name":"Strict (default)","title":"Strict (default)","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Strict mode catches \"fire-and-forget\" patterns where the producer calls\n`write()` without awaiting, which would cause unbounded memory growth.\nIt limits the buffer to `budget` bytes and the pending writes queue\nto a single entry.\n\nIf you properly await each write, you can only ever have one pending\nwrite at a time (yours), so you never hit the pending writes limit.\nUnawaited writes accumulate in the pending queue and throw once it\noverflows:\n\n```mjs\nimport { push, text } from 'node:stream/iter';\n\nconst { writer, readable } = push({ budget: 16384 });\n\n// Consumer must run concurrently -- without it, the first write\n// that fills the buffer blocks the producer forever.\nconst consuming = text(readable);\n\n// GOOD: awaited writes. The producer waits for the consumer to\n// make room when the buffer is full.\nfor (const item of dataset) {\n  await writer.write(item);\n}\nawait writer.end();\nconsole.log(await consuming);\n```\n\n```cjs\nconst { push, text } = require('node:stream/iter');\n\nasync function run() {\n  const { writer, readable } = push({ budget: 16384 });\n\n  // Consumer must run concurrently -- without it, the first write\n  // that fills the buffer blocks the producer forever.\n  const consuming = text(readable);\n\n  // GOOD: awaited writes. The producer waits for the consumer to\n  // make room when the buffer is full.\n  for (const item of dataset) {\n    await writer.write(item);\n  }\n  await writer.end();\n  console.log(await consuming);\n}\n\nrun().catch(console.error);\n```\n\nForgetting to `await` will eventually throw:\n\n```js\n// BAD: fire-and-forget. Strict mode throws once both buffers fill.\nfor (const item of dataset) {\n  writer.write(item); // Not awaited -- queues without bound\n}\n// --> throws \"Backpressure violation: too many pending writes\"\n```","summary":"Strict mode catches \"fire-and-forget\" patterns where the producer calls `write()` without awaiting, which would cause unbounded memory growth. It limits the buffer to `budget` bytes and the pending writes queue to a single entry.","examples":[{"language":"mjs","displayName":null,"code":"import { push, text } from 'node:stream/iter';\n\nconst { writer, readable } = push({ budget: 16384 });\n\n// Consumer must run concurrently -- without it, the first write\n// that fills the buffer blocks the producer forever.\nconst consuming = text(readable);\n\n// GOOD: awaited writes. The producer waits for the consumer to\n// make room when the buffer is full.\nfor (const item of dataset) {\n  await writer.write(item);\n}\nawait writer.end();\nconsole.log(await consuming);"},{"language":"cjs","displayName":null,"code":"const { push, text } = require('node:stream/iter');\n\nasync function run() {\n  const { writer, readable } = push({ budget: 16384 });\n\n  // Consumer must run concurrently -- without it, the first write\n  // that fills the buffer blocks the producer forever.\n  const consuming = text(readable);\n\n  // GOOD: awaited writes. The producer waits for the consumer to\n  // make room when the buffer is full.\n  for (const item of dataset) {\n    await writer.write(item);\n  }\n  await writer.end();\n  console.log(await consuming);\n}\n\nrun().catch(console.error);"},{"language":"js","displayName":null,"code":"// BAD: fire-and-forget. Strict mode throws once both buffers fill.\nfor (const item of dataset) {\n  writer.write(item); // Not awaited -- queues without bound\n}\n// --> throws \"Backpressure violation: too many pending writes\""}],"children":[]},{"kind":"section","id":"unbounded","name":"Unbounded","title":"Unbounded","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Unbounded mode caps buffered bytes at `budget` but places no limit on the\npending writes queue. Awaited writes block until the consumer makes room,\njust like strict mode. The difference is that unawaited writes silently\nqueue forever instead of throwing -- a potential memory leak if the\nproducer forgets to `await`.\n\nThis is the mode that existing Node.js classic streams and Web Streams\ndefault to. Use it when you control the producer and know it awaits\nproperly, or when migrating code from those APIs.\n\n```mjs\nimport { push, text } from 'node:stream/iter';\n\nconst { writer, readable } = push({\n  budget: 16384,\n  backpressure: 'unbounded',\n});\n\nconst consuming = text(readable);\n\n// Safe -- awaited writes block until the consumer reads.\nfor (const item of dataset) {\n  await writer.write(item);\n}\nawait writer.end();\nconsole.log(await consuming);\n```\n\n```cjs\nconst { push, text } = require('node:stream/iter');\n\nasync function run() {\n  const { writer, readable } = push({\n    budget: 16384,\n    backpressure: 'unbounded',\n  });\n\n  const consuming = text(readable);\n\n  // Safe -- awaited writes block until the consumer reads.\n  for (const item of dataset) {\n    await writer.write(item);\n  }\n  await writer.end();\n  console.log(await consuming);\n}\n\nrun().catch(console.error);\n```","summary":"Unbounded mode caps buffered bytes at `budget` but places no limit on the pending writes queue. Awaited writes block until the consumer makes room, just like strict mode. The difference is that unawaited writes silently queue forever instead of throwing -- a potential memory leak if the producer forgets to `await`.","examples":[{"language":"mjs","displayName":null,"code":"import { push, text } from 'node:stream/iter';\n\nconst { writer, readable } = push({\n  budget: 16384,\n  backpressure: 'unbounded',\n});\n\nconst consuming = text(readable);\n\n// Safe -- awaited writes block until the consumer reads.\nfor (const item of dataset) {\n  await writer.write(item);\n}\nawait writer.end();\nconsole.log(await consuming);"},{"language":"cjs","displayName":null,"code":"const { push, text } = require('node:stream/iter');\n\nasync function run() {\n  const { writer, readable } = push({\n    budget: 16384,\n    backpressure: 'unbounded',\n  });\n\n  const consuming = text(readable);\n\n  // Safe -- awaited writes block until the consumer reads.\n  for (const item of dataset) {\n    await writer.write(item);\n  }\n  await writer.end();\n  console.log(await consuming);\n}\n\nrun().catch(console.error);"}],"children":[]},{"kind":"section","id":"drop-oldest","name":"Drop-oldest","title":"Drop-oldest","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Writes never wait. When the slots buffer is full, the oldest buffered\nchunk is evicted to make room for the incoming write. The consumer\nalways sees the most recent data. Useful for live feeds, telemetry, or\nany scenario where stale data is less valuable than current data.\n\n```mjs\nimport { push } from 'node:stream/iter';\n\n// Keep only the most recent ~16 KB of readings\nconst { writer, readable } = push({\n  budget: 16384,\n  backpressure: 'drop-oldest',\n});\n```\n\n```cjs\nconst { push } = require('node:stream/iter');\n\n// Keep only the most recent ~16 KB of readings\nconst { writer, readable } = push({\n  budget: 16384,\n  backpressure: 'drop-oldest',\n});\n```","summary":"Writes never wait. When the slots buffer is full, the oldest buffered chunk is evicted to make room for the incoming write. The consumer always sees the most recent data. Useful for live feeds, telemetry, or any scenario where stale data is less valuable than current data.","examples":[{"language":"mjs","displayName":null,"code":"import { push } from 'node:stream/iter';\n\n// Keep only the most recent ~16 KB of readings\nconst { writer, readable } = push({\n  budget: 16384,\n  backpressure: 'drop-oldest',\n});"},{"language":"cjs","displayName":null,"code":"const { push } = require('node:stream/iter');\n\n// Keep only the most recent ~16 KB of readings\nconst { writer, readable } = push({\n  budget: 16384,\n  backpressure: 'drop-oldest',\n});"}],"children":[]},{"kind":"section","id":"drop-newest","name":"Drop-newest","title":"Drop-newest","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Writes never wait. When the slots buffer is full, the incoming write is\nsilently discarded. The consumer processes what is already buffered\nwithout being overwhelmed by new data. Useful for rate-limiting or\nshedding load under pressure.\n\n```mjs\nimport { push } from 'node:stream/iter';\n\n// Accept up to 16 KB of buffered data; discard anything beyond that\nconst { writer, readable } = push({\n  budget: 16384,\n  backpressure: 'drop-newest',\n});\n```\n\n```cjs\nconst { push } = require('node:stream/iter');\n\n// Accept up to 16 KB of buffered data; discard anything beyond that\nconst { writer, readable } = push({\n  budget: 16384,\n  backpressure: 'drop-newest',\n});\n```","summary":"Writes never wait. When the slots buffer is full, the incoming write is silently discarded. The consumer processes what is already buffered without being overwhelmed by new data. Useful for rate-limiting or shedding load under pressure.","examples":[{"language":"mjs","displayName":null,"code":"import { push } from 'node:stream/iter';\n\n// Accept up to 16 KB of buffered data; discard anything beyond that\nconst { writer, readable } = push({\n  budget: 16384,\n  backpressure: 'drop-newest',\n});"},{"language":"cjs","displayName":null,"code":"const { push } = require('node:stream/iter');\n\n// Accept up to 16 KB of buffered data; discard anything beyond that\nconst { writer, readable } = push({\n  budget: 16384,\n  backpressure: 'drop-newest',\n});"}],"children":[]}]},{"kind":"section","id":"writer-interface","name":"Writer interface","title":"Writer interface","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"A writer is any object conforming to the Writer interface. Only `write()` is\nrequired; all other methods are optional.\n\nEach async method has a synchronous `*Sync` counterpart designed for a\ntry-fallback pattern: attempt the fast synchronous path first, and fall back\nto the async version only when the synchronous call indicates it could not\ncomplete:\n\n```mjs\nif (!writer.writeSync(chunk)) await writer.write(chunk);\nif (!writer.writevSync(chunks)) await writer.writev(chunks);\nif (writer.endSync() < 0) await writer.end();\nwriter.fail(err);  // Always synchronous, no fallback needed\n```","summary":"A writer is any object conforming to the Writer interface. Only `write()` is required; all other methods are optional.","examples":[{"language":"mjs","displayName":null,"code":"if (!writer.writeSync(chunk)) await writer.write(chunk);\nif (!writer.writevSync(chunks)) await writer.writev(chunks);\nif (writer.endSync() < 0) await writer.end();\nwriter.fail(err);  // Always synchronous, no fallback needed"}],"children":[{"kind":"property","id":"writercanwrite","name":"canWrite","title":"`writer.canWrite`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean | null","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7},{"name":"null","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type","start":10,"end":14}]},"default":null,"description":"Returns `true` if the next write is likely to be accepted (buffered data is\nbelow capacity), `false` if backpressure is active, or `null` if the writer\nis closed or the consumer has disconnected.\n\nThis is a hint, not a guarantee: the state can change between the check and\nthe write. Use [`ondrain()`](#ondraindrainable) to wait for capacity rather than polling.","summary":"Returns `true` if the next write is likely to be accepted (buffered data is below capacity), `false` if backpressure is active, or `null` if the writer is closed or the consumer has disconnected.","examples":[],"children":[]},{"kind":"method","id":"writerendoptions","name":"end","title":"`writer.end([options])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"Cancel just this operation. The signal cancels only\nthe pending `end()` call; it does not fail the writer itself.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Promise","links":[{"name":"Promise","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise","start":0,"end":7}]},"description":"Fulfills with the total number of bytes written."}},"description":"Signals that no more data will be written and waits for buffered data to drain.","summary":"Signals that no more data will be written and waits for buffered data to drain.","examples":[],"children":[]},{"kind":"method","id":"writerendsync","name":"endSync","title":"`writer.endSync()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Total bytes written, or `-1` if ending cannot complete\nsynchronously."}},"description":"Synchronous variant of `writer.end()`. A return value of `-1` means closing has\nstarted but requires asynchronous draining. Use the try-fallback pattern to\nawait completion:\n\n```cjs\nconst result = writer.endSync();\nif (result < 0) {\n  writer.end();\n}\n```","summary":"Synchronous variant of `writer.end()`. A return value of `-1` means closing has started but requires asynchronous draining. Use the try-fallback pattern to await completion:","examples":[{"language":"cjs","displayName":null,"code":"const result = writer.endSync();\nif (result < 0) {\n  writer.end();\n}"}],"children":[]},{"kind":"method","id":"writerfailreason","name":"fail","title":"`writer.fail(reason)`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"reason","type":{"text":"any","links":[{"name":"any","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types","start":0,"end":3}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Put the writer into a terminal error state. If the writer is already closed\nor errored, this is a no-op. Unlike `write()` and `end()`, `fail()` is\nunconditionally synchronous because failing a writer is a pure state\ntransition with no async work to perform.","summary":"Put the writer into a terminal error state. If the writer is already closed or errored, this is a no-op. Unlike `write()` and `end()`, `fail()` is unconditionally synchronous because failing a writer is a pure state transition with no async work to perform.","examples":[],"children":[]},{"kind":"method","id":"writerwritechunk-options","name":"write","title":"`writer.write(chunk[, options])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"chunk","type":{"text":"Uint8Array | string","links":[{"name":"Uint8Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array","start":0,"end":10},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":13,"end":19}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"Cancel just this write operation. The signal cancels\nonly the pending `write()` call; it does not fail the writer itself.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Promise","links":[{"name":"Promise","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise","start":0,"end":7}]},"description":"Fulfills with `undefined` when buffer space is available."}},"description":"Write a chunk.","summary":"Write a chunk.","examples":[],"children":[]},{"kind":"method","id":"writerwritesyncchunk","name":"writeSync","title":"`writer.writeSync(chunk)`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"chunk","type":{"text":"Uint8Array | string","links":[{"name":"Uint8Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array","start":0,"end":10},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":13,"end":19}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` if the write was accepted, `false` if the\nbuffer is full."}},"description":"Synchronous write. Does not block; returns `false` if backpressure is active.","summary":"Synchronous write. Does not block; returns `false` if backpressure is active.","examples":[],"children":[]},{"kind":"method","id":"writerwritevchunks-options","name":"writev","title":"`writer.writev(chunks[, options])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"chunks","type":{"text":"Uint8Array[] | string[]","links":[{"name":"Uint8Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array","start":0,"end":10},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":15,"end":21}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"Cancel just this write operation. The signal cancels\nonly the pending `writev()` call; it does not fail the writer itself.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Promise","links":[{"name":"Promise","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise","start":0,"end":7}]},"description":""}},"description":"Write multiple chunks as a single batch.","summary":"Write multiple chunks as a single batch.","examples":[],"children":[]},{"kind":"method","id":"writerwritevsyncchunks","name":"writevSync","title":"`writer.writevSync(chunks)`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"chunks","type":{"text":"Uint8Array[] | string[]","links":[{"name":"Uint8Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array","start":0,"end":10},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":15,"end":21}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` if the write was accepted, `false` if the\nbuffer is full."}},"description":"Synchronous batch write.","summary":"Synchronous batch write.","examples":[],"children":[]}]}]},{"kind":"section","id":"the-streamiter-module","name":"The stream/iter module","title":"The `stream/iter` module","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"All functions are available both as named exports and as properties of the\n`Stream` namespace object:\n\n```mjs\n// Named exports\nimport { from, pull, bytes, Stream } from 'node:stream/iter';\n\n// Namespace access\nStream.from('hello');\n```\n\n```cjs\n// Named exports\nconst { from, pull, bytes, Stream } = require('node:stream/iter');\n\n// Namespace access\nStream.from('hello');\n```\n\nIncluding the `node:` prefix on the module specifier is optional.","summary":"All functions are available both as named exports and as properties of the `Stream` namespace object:","examples":[{"language":"mjs","displayName":null,"code":"// Named exports\nimport { from, pull, bytes, Stream } from 'node:stream/iter';\n\n// Namespace access\nStream.from('hello');"},{"language":"cjs","displayName":null,"code":"// Named exports\nconst { from, pull, bytes, Stream } = require('node:stream/iter');\n\n// Namespace access\nStream.from('hello');"}],"children":[]},{"kind":"section","id":"sources","name":"Sources","title":"Sources","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"method","id":"frominput","name":"from","title":"`from(input)`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"input","type":{"text":"string | ArrayBuffer | ArrayBufferView | Iterable | AsyncIterable | Object","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"ArrayBuffer","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer","start":9,"end":20},{"name":"ArrayBufferView","href":"https://developer.mozilla.org/docs/Web/API/ArrayBufferView","start":23,"end":38},{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":41,"end":49},{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":52,"end":65},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":68,"end":74}]},"description":"Must not be `null` or `undefined`.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"AsyncIterable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13}]},"description":"whose chunks fulfill with {Uint8Array[]}."}},"description":"Create an async byte stream from the given input. Strings are UTF-8 encoded.\n`ArrayBuffer` and `ArrayBufferView` values are wrapped as `Uint8Array`. Arrays\nand iterables in `input` are recursively flattened and normalized.\n\nObjects implementing `Symbol.for('Stream.toAsyncStreamable')` or\n`Symbol.for('Stream.toStreamable')` are converted via those protocols. The\n`toAsyncStreamable` protocol takes precedence over `toStreamable`, which takes\nprecedence over the iteration protocols (`Symbol.asyncIterator`,\n`Symbol.iterator`).\n\n```mjs\nimport { Buffer } from 'node:buffer';\nimport { from, text } from 'node:stream/iter';\n\nconsole.log(await text(from('hello')));       // 'hello'\nconsole.log(await text(from(Buffer.from('hello')))); // 'hello'\n```\n\n```cjs\nconst { Buffer } = require('node:buffer');\nconst { from, text } = require('node:stream/iter');\n\nasync function run() {\n  console.log(await text(from('hello')));       // 'hello'\n  console.log(await text(from(Buffer.from('hello')))); // 'hello'\n}\n\nrun().catch(console.error);\n```","summary":"Create an async byte stream from the given input. Strings are UTF-8 encoded. `ArrayBuffer` and `ArrayBufferView` values are wrapped as `Uint8Array`. Arrays and iterables in `input` are recursively flattened and normalized.","examples":[{"language":"mjs","displayName":null,"code":"import { Buffer } from 'node:buffer';\nimport { from, text } from 'node:stream/iter';\n\nconsole.log(await text(from('hello')));       // 'hello'\nconsole.log(await text(from(Buffer.from('hello')))); // 'hello'"},{"language":"cjs","displayName":null,"code":"const { Buffer } = require('node:buffer');\nconst { from, text } = require('node:stream/iter');\n\nasync function run() {\n  console.log(await text(from('hello')));       // 'hello'\n  console.log(await text(from(Buffer.from('hello')))); // 'hello'\n}\n\nrun().catch(console.error);"}],"children":[]},{"kind":"method","id":"fromsyncinput","name":"fromSync","title":"`fromSync(input)`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"input","type":{"text":"string | ArrayBuffer | ArrayBufferView | Iterable | Object","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"ArrayBuffer","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer","start":9,"end":20},{"name":"ArrayBufferView","href":"https://developer.mozilla.org/docs/Web/API/ArrayBufferView","start":23,"end":38},{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":41,"end":49},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":52,"end":58}]},"description":"Must not be `null` or `undefined`.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"Iterable","links":[{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":0,"end":8}]},"description":"whose chunks return {Uint8Array[]}"}},"description":"Synchronous version of [`from()`](#frominput). Returns a sync iterable. Cannot accept\nasync iterables or promises. Objects implementing\n`Symbol.for('Stream.toStreamable')` are converted via that protocol (takes\nprecedence over `Symbol.iterator`). The `toAsyncStreamable` protocol is\nignored entirely.\n\n```mjs\nimport { fromSync, textSync } from 'node:stream/iter';\n\nconsole.log(textSync(fromSync('hello'))); // 'hello'\n```\n\n```cjs\nconst { fromSync, textSync } = require('node:stream/iter');\n\nconsole.log(textSync(fromSync('hello'))); // 'hello'\n```","summary":"Synchronous version of `from()`. Returns a sync iterable. Cannot accept async iterables or promises. Objects implementing `Symbol.for('Stream.toStreamable')` are converted via that protocol (takes precedence over `Symbol.iterator`). The `toAsyncStreamable` protocol is ignored entirely.","examples":[{"language":"mjs","displayName":null,"code":"import { fromSync, textSync } from 'node:stream/iter';\n\nconsole.log(textSync(fromSync('hello'))); // 'hello'"},{"language":"cjs","displayName":null,"code":"const { fromSync, textSync } = require('node:stream/iter');\n\nconsole.log(textSync(fromSync('hello'))); // 'hello'"}],"children":[]}]},{"kind":"section","id":"pipelines","name":"Pipelines","title":"Pipelines","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"method","id":"pipetosource-transforms-writer-options","name":"pipeTo","title":"`pipeTo(source[, ...transforms], writer[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"AsyncIterable | Iterable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13},{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":16,"end":24}]},"description":"The data source.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"transforms","type":{"text":"Function | Object","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":11,"end":17}]},"description":"Zero or more transforms to apply.","default":null,"optional":true,"rest":true,"properties":[]},{"name":"writer","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"Destination with `write(chunk)` method.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"Abort the pipeline.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"preventClose","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If `true`, do not call `writer.end()` when\nthe source ends.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"preventFail","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If `true`, do not call `writer.fail()` on\nerror.","default":"false","optional":true,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Promise","links":[{"name":"Promise","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise","start":0,"end":7}]},"description":"Fulfills with the total number of bytes written."}},"description":"Pipe a source through transforms into a writer. If the writer has a\n`writev(chunks)` method, entire batches are passed in a single call (enabling\nscatter/gather I/O).\n\nIf the writer implements the optional `*Sync` methods (`writeSync`, `writevSync`,\n`endSync`), `pipeTo()` will attempt to use the synchronous methods\nfirst as a fast path, and fall back to the async versions only when the sync\nmethods indicate they cannot complete (e.g., backpressure or waiting for the\nnext tick). `fail()` is always called synchronously.\n\n```mjs\nimport { from, pipeTo } from 'node:stream/iter';\nimport { compressGzip } from 'node:zlib/iter';\nimport { open } from 'node:fs/promises';\n\nconst fh = await open('output.gz', 'w');\nconst totalBytes = await pipeTo(\n  from('Hello, world!'),\n  compressGzip(),\n  fh.writer({ autoClose: true }),\n);\n```\n\n```cjs\nconst { from, pipeTo } = require('node:stream/iter');\nconst { compressGzip } = require('node:zlib/iter');\nconst { open } = require('node:fs/promises');\n\nasync function run() {\n  const fh = await open('output.gz', 'w');\n  const totalBytes = await pipeTo(\n    from('Hello, world!'),\n    compressGzip(),\n    fh.writer({ autoClose: true }),\n  );\n}\n\nrun().catch(console.error);\n```","summary":"Pipe a source through transforms into a writer. If the writer has a `writev(chunks)` method, entire batches are passed in a single call (enabling scatter/gather I/O).","examples":[{"language":"mjs","displayName":null,"code":"import { from, pipeTo } from 'node:stream/iter';\nimport { compressGzip } from 'node:zlib/iter';\nimport { open } from 'node:fs/promises';\n\nconst fh = await open('output.gz', 'w');\nconst totalBytes = await pipeTo(\n  from('Hello, world!'),\n  compressGzip(),\n  fh.writer({ autoClose: true }),\n);"},{"language":"cjs","displayName":null,"code":"const { from, pipeTo } = require('node:stream/iter');\nconst { compressGzip } = require('node:zlib/iter');\nconst { open } = require('node:fs/promises');\n\nasync function run() {\n  const fh = await open('output.gz', 'w');\n  const totalBytes = await pipeTo(\n    from('Hello, world!'),\n    compressGzip(),\n    fh.writer({ autoClose: true }),\n  );\n}\n\nrun().catch(console.error);"}],"children":[]},{"kind":"method","id":"pipetosyncsource-transforms-writer-options","name":"pipeToSync","title":"`pipeToSync(source[, ...transforms], writer[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"Iterable","links":[{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":0,"end":8}]},"description":"The sync data source.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"transforms","type":{"text":"Function | Object","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":11,"end":17}]},"description":"Zero or more sync transforms.","default":null,"optional":true,"rest":true,"properties":[]},{"name":"writer","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"Destination with `write(chunk)` method.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"preventClose","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"","default":"false","optional":true,"rest":false,"properties":[]},{"name":"preventFail","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"","default":"false","optional":true,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Total bytes written."}},"description":"Synchronous version of [`pipeTo()`](#pipetosource-transforms-writer-options). The `source`, all transforms, and the\n`writer` must be synchronous. Cannot accept async iterables or promises.\n\nThe `writer` must have the `*Sync` methods (`writeSync`, `writevSync`,\n`endSync`) and `fail()` for this to work.","summary":"Synchronous version of `pipeTo()`. The `source`, all transforms, and the `writer` must be synchronous. Cannot accept async iterables or promises.","examples":[],"children":[]},{"kind":"method","id":"pullsource-transforms-options","name":"pull","title":"`pull(source[, ...transforms][, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"AsyncIterable | Iterable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13},{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":16,"end":24}]},"description":"The data source.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"transforms","type":{"text":"Function | Object","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":11,"end":17}]},"description":"Zero or more transforms to apply.","default":null,"optional":true,"rest":true,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"Abort the pipeline.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"AsyncIterable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13}]},"description":"whose chunks fulfill with {Uint8Array[]}"}},"description":"Create a lazy async pipeline. Data is not read from `source` until the\nreturned iterable is consumed. Transforms are applied in order.\n\n```mjs\nimport { from, pull, text } from 'node:stream/iter';\n\nconst asciiUpper = (chunks) => {\n  if (chunks === null) return null;\n  return chunks.map((c) => {\n    for (let i = 0; i < c.length; i++) {\n      c[i] -= (c[i] >= 97 && c[i] <= 122) * 32;\n    }\n    return c;\n  });\n};\n\nconst result = pull(from('hello'), asciiUpper);\nconsole.log(await text(result)); // 'HELLO'\n```\n\n```cjs\nconst { from, pull, text } = require('node:stream/iter');\n\nconst asciiUpper = (chunks) => {\n  if (chunks === null) return null;\n  return chunks.map((c) => {\n    for (let i = 0; i < c.length; i++) {\n      c[i] -= (c[i] >= 97 && c[i] <= 122) * 32;\n    }\n    return c;\n  });\n};\n\nasync function run() {\n  const result = pull(from('hello'), asciiUpper);\n  console.log(await text(result)); // 'HELLO'\n}\n\nrun().catch(console.error);\n```\n\nUsing an `AbortSignal`:\n\n```mjs\nimport { pull } from 'node:stream/iter';\n\nconst ac = new AbortController();\nconst result = pull(source, transform, { signal: ac.signal });\nac.abort(); // Pipeline throws AbortError on next iteration\n```\n\n```cjs\nconst { pull } = require('node:stream/iter');\n\nconst ac = new AbortController();\nconst result = pull(source, transform, { signal: ac.signal });\nac.abort(); // Pipeline throws AbortError on next iteration\n```","summary":"Create a lazy async pipeline. Data is not read from `source` until the returned iterable is consumed. Transforms are applied in order.","examples":[{"language":"mjs","displayName":null,"code":"import { from, pull, text } from 'node:stream/iter';\n\nconst asciiUpper = (chunks) => {\n  if (chunks === null) return null;\n  return chunks.map((c) => {\n    for (let i = 0; i < c.length; i++) {\n      c[i] -= (c[i] >= 97 && c[i] <= 122) * 32;\n    }\n    return c;\n  });\n};\n\nconst result = pull(from('hello'), asciiUpper);\nconsole.log(await text(result)); // 'HELLO'"},{"language":"cjs","displayName":null,"code":"const { from, pull, text } = require('node:stream/iter');\n\nconst asciiUpper = (chunks) => {\n  if (chunks === null) return null;\n  return chunks.map((c) => {\n    for (let i = 0; i < c.length; i++) {\n      c[i] -= (c[i] >= 97 && c[i] <= 122) * 32;\n    }\n    return c;\n  });\n};\n\nasync function run() {\n  const result = pull(from('hello'), asciiUpper);\n  console.log(await text(result)); // 'HELLO'\n}\n\nrun().catch(console.error);"},{"language":"mjs","displayName":null,"code":"import { pull } from 'node:stream/iter';\n\nconst ac = new AbortController();\nconst result = pull(source, transform, { signal: ac.signal });\nac.abort(); // Pipeline throws AbortError on next iteration"},{"language":"cjs","displayName":null,"code":"const { pull } = require('node:stream/iter');\n\nconst ac = new AbortController();\nconst result = pull(source, transform, { signal: ac.signal });\nac.abort(); // Pipeline throws AbortError on next iteration"}],"children":[]},{"kind":"method","id":"pullsyncsource-transforms","name":"pullSync","title":"`pullSync(source[, ...transforms])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"Iterable","links":[{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":0,"end":8}]},"description":"The sync data source.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"transforms","type":{"text":"Function | Object","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":11,"end":17}]},"description":"Zero or more sync transforms.","default":null,"optional":true,"rest":true,"properties":[]}],"returns":{"type":{"text":"Iterable","links":[{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":0,"end":8}]},"description":"whose chunks return {Uint8Array[]}"}},"description":"Synchronous version of [`pull()`](#pullsource-transforms-options). All transforms must be synchronous.","summary":"Synchronous version of `pull()`. All transforms must be synchronous.","examples":[],"children":[]}]},{"kind":"section","id":"push-streams","name":"Push streams","title":"Push streams","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"method","id":"pushtransforms-options","name":"push","title":"`push([...transforms][, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"transforms","type":{"text":"Function | Object","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":11,"end":17}]},"description":"Optional transforms applied to the\nreadable side.","default":null,"optional":true,"rest":true,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"budget","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Maximum number of buffered bytes before\nbackpressure is applied. Must be >= 16384.","default":"16384","optional":true,"rest":false,"properties":[]},{"name":"backpressure","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Backpressure policy: `'strict'`, `'unbounded'`,\n`'drop-oldest'`, or `'drop-newest'`.","default":"'strict'","optional":true,"rest":false,"properties":[]},{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"Abort the stream.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":""}},"description":"Create a push stream with backpressure. The writer pushes data in; the\nreadable side is consumed as an async iterable.\n\n```mjs\nimport { push, text } from 'node:stream/iter';\n\nconst { writer, readable } = push();\n\n// Producer and consumer must run concurrently. With strict backpressure\n// (the default), awaited writes block until the consumer reads.\nconst producing = (async () => {\n  await writer.write('hello');\n  await writer.write(' world');\n  await writer.end();\n})();\n\nconsole.log(await text(readable)); // 'hello world'\nawait producing;\n```\n\n```cjs\nconst { push, text } = require('node:stream/iter');\n\nasync function run() {\n  const { writer, readable } = push();\n\n  // Producer and consumer must run concurrently. With strict backpressure\n  // (the default), awaited writes block until the consumer reads.\n  const producing = (async () => {\n    await writer.write('hello');\n    await writer.write(' world');\n    await writer.end();\n  })();\n\n  console.log(await text(readable)); // 'hello world'\n  await producing;\n}\n\nrun().catch(console.error);\n```\n\nThe writer returned by `push()` conforms to the \\[Writer interface]\\[].","summary":"Create a push stream with backpressure. The writer pushes data in; the readable side is consumed as an async iterable.","examples":[{"language":"mjs","displayName":null,"code":"import { push, text } from 'node:stream/iter';\n\nconst { writer, readable } = push();\n\n// Producer and consumer must run concurrently. With strict backpressure\n// (the default), awaited writes block until the consumer reads.\nconst producing = (async () => {\n  await writer.write('hello');\n  await writer.write(' world');\n  await writer.end();\n})();\n\nconsole.log(await text(readable)); // 'hello world'\nawait producing;"},{"language":"cjs","displayName":null,"code":"const { push, text } = require('node:stream/iter');\n\nasync function run() {\n  const { writer, readable } = push();\n\n  // Producer and consumer must run concurrently. With strict backpressure\n  // (the default), awaited writes block until the consumer reads.\n  const producing = (async () => {\n    await writer.write('hello');\n    await writer.write(' world');\n    await writer.end();\n  })();\n\n  console.log(await text(readable)); // 'hello world'\n  await producing;\n}\n\nrun().catch(console.error);"}],"children":[]}]},{"kind":"section","id":"duplex-channels","name":"Duplex channels","title":"Duplex channels","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"method","id":"duplexoptions","name":"duplex","title":"`duplex([options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"budget","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Buffer size in bytes for both directions.","default":"16384","optional":true,"rest":false,"properties":[]},{"name":"backpressure","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Policy for both directions.","default":"'strict'","optional":true,"rest":false,"properties":[]},{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"Cancellation signal for both channels.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"a","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"Options specific to the A-to-B direction. Overrides\nshared options.","default":null,"optional":false,"rest":false,"properties":[{"name":"budget","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"backpressure","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}]},{"name":"b","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"Options specific to the B-to-A direction. Overrides\nshared options.","default":null,"optional":false,"rest":false,"properties":[{"name":"budget","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"backpressure","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}]}]}],"returns":{"type":{"text":"Array","links":[{"name":"Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array","start":0,"end":5}]},"description":"A pair `[channelA, channelB]` of duplex channels."}},"description":"Create a pair of connected duplex channels for bidirectional communication,\nsimilar to `socketpair()`. Data written to one channel's writer appears in\nthe other channel's readable.\n\nEach channel has:\n\n* `writer` — a \\[Writer interface]\\[] object for sending data to the peer.\n* `readable` — an {AsyncIterable} for reading data from the peer.\n* `close()` — close this end of the channel (idempotent).\n* `[Symbol.asyncDispose]()` — async dispose support for `await using`.\n\n```mjs\nimport { duplex, text } from 'node:stream/iter';\n\nconst [client, server] = duplex();\n\n// Server echoes back\nconst serving = (async () => {\n  for await (const chunks of server.readable) {\n    await server.writer.writev(chunks);\n  }\n})();\n\nawait client.writer.write('hello');\nawait client.writer.end();\n\nconsole.log(await text(server.readable)); // handled by echo\nawait serving;\n```\n\n```cjs\nconst { duplex, text } = require('node:stream/iter');\n\nasync function run() {\n  const [client, server] = duplex();\n\n  // Server echoes back\n  const serving = (async () => {\n    for await (const chunks of server.readable) {\n      await server.writer.writev(chunks);\n    }\n  })();\n\n  await client.writer.write('hello');\n  await client.writer.end();\n\n  console.log(await text(server.readable)); // handled by echo\n  await serving;\n}\n\nrun().catch(console.error);\n```","summary":"Create a pair of connected duplex channels for bidirectional communication, similar to `socketpair()`. Data written to one channel's writer appears in the other channel's readable.","examples":[{"language":"mjs","displayName":null,"code":"import { duplex, text } from 'node:stream/iter';\n\nconst [client, server] = duplex();\n\n// Server echoes back\nconst serving = (async () => {\n  for await (const chunks of server.readable) {\n    await server.writer.writev(chunks);\n  }\n})();\n\nawait client.writer.write('hello');\nawait client.writer.end();\n\nconsole.log(await text(server.readable)); // handled by echo\nawait serving;"},{"language":"cjs","displayName":null,"code":"const { duplex, text } = require('node:stream/iter');\n\nasync function run() {\n  const [client, server] = duplex();\n\n  // Server echoes back\n  const serving = (async () => {\n    for await (const chunks of server.readable) {\n      await server.writer.writev(chunks);\n    }\n  })();\n\n  await client.writer.write('hello');\n  await client.writer.end();\n\n  console.log(await text(server.readable)); // handled by echo\n  await serving;\n}\n\nrun().catch(console.error);"}],"children":[]}]},{"kind":"section","id":"consumers","name":"Consumers","title":"Consumers","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"method","id":"arraysource-options","name":"array","title":"`array(source[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"AsyncIterable | Iterable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13},{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":16,"end":24}]},"description":"whose chunks must be {Uint8Array[]}","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"limit","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Maximum number of bytes to consume. If the total bytes\ncollected exceeds limit, an `ERR_OUT_OF_RANGE` error is thrown","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Promise","links":[{"name":"Promise","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise","start":0,"end":7}]},"description":"Fulfills with an array of `Uint8Array` objects."}},"description":"Collect all chunks as an array of `Uint8Array` values (without concatenating).","summary":"Collect all chunks as an array of `Uint8Array` values (without concatenating).","examples":[],"children":[]},{"kind":"method","id":"arraybuffersource-options","name":"arrayBuffer","title":"`arrayBuffer(source[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"AsyncIterable | Iterable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13},{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":16,"end":24}]},"description":"whose chunks must be {Uint8Array[]}","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"limit","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Maximum number of bytes to consume. If the total bytes\ncollected exceeds limit, an `ERR_OUT_OF_RANGE` error is thrown","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Promise","links":[{"name":"Promise","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise","start":0,"end":7}]},"description":"Fulfills with an `ArrayBuffer` object."}},"description":"Collect all bytes into an `ArrayBuffer`.","summary":"Collect all bytes into an `ArrayBuffer`.","examples":[],"children":[]},{"kind":"method","id":"arraybuffersyncsource-options","name":"arrayBufferSync","title":"`arrayBufferSync(source[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"Iterable","links":[{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":0,"end":8}]},"description":"whose chunks must be {Uint8Array[]}","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"limit","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Maximum number of bytes to consume. If the total bytes\ncollected exceeds limit, an `ERR_OUT_OF_RANGE` error is thrown","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"ArrayBuffer","links":[{"name":"ArrayBuffer","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer","start":0,"end":11}]},"description":""}},"description":"Synchronous version of [`arrayBuffer()`](#arraybuffersource-options).","summary":"Synchronous version of `arrayBuffer()`.","examples":[],"children":[]},{"kind":"method","id":"arraysyncsource-options","name":"arraySync","title":"`arraySync(source[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"Iterable","links":[{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":0,"end":8}]},"description":"whose chunks must be {Uint8Array[]}","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"limit","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Maximum number of bytes to consume. If the total bytes\ncollected exceeds limit, an `ERR_OUT_OF_RANGE` error is thrown","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Uint8Array[]","links":[{"name":"Uint8Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array","start":0,"end":10}]},"description":""}},"description":"Synchronous version of [`array()`](#arraysource-options).","summary":"Synchronous version of `array()`.","examples":[],"children":[]},{"kind":"method","id":"bytessource-options","name":"bytes","title":"`bytes(source[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"AsyncIterable | Iterable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13},{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":16,"end":24}]},"description":"whose chunks must be {Uint8Array[]}","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"limit","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Maximum number of bytes to consume. If the total bytes\ncollected exceeds limit, an `ERR_OUT_OF_RANGE` error is thrown","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Promise","links":[{"name":"Promise","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise","start":0,"end":7}]},"description":"Fulfills with an `Uint8Array` object."}},"description":"Collect all bytes from a stream into a single `Uint8Array`.\n\n```mjs\nimport { from, bytes } from 'node:stream/iter';\n\nconst data = await bytes(from('hello'));\nconsole.log(data); // Uint8Array(5) [ 104, 101, 108, 108, 111 ]\n```\n\n```cjs\nconst { from, bytes } = require('node:stream/iter');\n\nasync function run() {\n  const data = await bytes(from('hello'));\n  console.log(data); // Uint8Array(5) [ 104, 101, 108, 108, 111 ]\n}\n\nrun().catch(console.error);\n```","summary":"Collect all bytes from a stream into a single `Uint8Array`.","examples":[{"language":"mjs","displayName":null,"code":"import { from, bytes } from 'node:stream/iter';\n\nconst data = await bytes(from('hello'));\nconsole.log(data); // Uint8Array(5) [ 104, 101, 108, 108, 111 ]"},{"language":"cjs","displayName":null,"code":"const { from, bytes } = require('node:stream/iter');\n\nasync function run() {\n  const data = await bytes(from('hello'));\n  console.log(data); // Uint8Array(5) [ 104, 101, 108, 108, 111 ]\n}\n\nrun().catch(console.error);"}],"children":[]},{"kind":"method","id":"bytessyncsource-options","name":"bytesSync","title":"`bytesSync(source[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"Iterable","links":[{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":0,"end":8}]},"description":"whose chunks must be {Uint8Array[]}","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"limit","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Maximum number of bytes to consume. If the total bytes\ncollected exceeds limit, an `ERR_OUT_OF_RANGE` error is thrown","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Uint8Array","links":[{"name":"Uint8Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array","start":0,"end":10}]},"description":""}},"description":"Synchronous version of [`bytes()`](#bytessource-options).","summary":"Synchronous version of `bytes()`.","examples":[],"children":[]},{"kind":"method","id":"textsource-options","name":"text","title":"`text(source[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"AsyncIterable | Iterable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13},{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":16,"end":24}]},"description":"whose chunks must be {Uint8Array[]}","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"encoding","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Text encoding.","default":"'utf-8'","optional":true,"rest":false,"properties":[]},{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"limit","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Maximum number of bytes to consume. If the total bytes\ncollected exceeds limit, an `ERR_OUT_OF_RANGE` error is thrown","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Promise","links":[{"name":"Promise","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise","start":0,"end":7}]},"description":"Fulfills with a `string`."}},"description":"Collect all bytes and decode as text.\n\n```mjs\nimport { from, text } from 'node:stream/iter';\n\nconsole.log(await text(from('hello'))); // 'hello'\n```\n\n```cjs\nconst { from, text } = require('node:stream/iter');\n\nasync function run() {\n  console.log(await text(from('hello'))); // 'hello'\n}\n\nrun().catch(console.error);\n```","summary":"Collect all bytes and decode as text.","examples":[{"language":"mjs","displayName":null,"code":"import { from, text } from 'node:stream/iter';\n\nconsole.log(await text(from('hello'))); // 'hello'"},{"language":"cjs","displayName":null,"code":"const { from, text } = require('node:stream/iter');\n\nasync function run() {\n  console.log(await text(from('hello'))); // 'hello'\n}\n\nrun().catch(console.error);"}],"children":[]},{"kind":"method","id":"textsyncsource-options","name":"textSync","title":"`textSync(source[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"Iterable","links":[{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":0,"end":8}]},"description":"whose chunks must be {Uint8Array[]}","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"encoding","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":"'utf-8'","optional":true,"rest":false,"properties":[]},{"name":"limit","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Maximum number of bytes to consume. If the total bytes\ncollected exceeds limit, an `ERR_OUT_OF_RANGE` error is thrown","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"Synchronous version of [`text()`](#textsource-options).","summary":"Synchronous version of `text()`.","examples":[],"children":[]}]},{"kind":"section","id":"utilities","name":"Utilities","title":"Utilities","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"method","id":"ondraindrainable","name":"ondrain","title":"`ondrain(drainable)`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"drainable","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"An object implementing the drainable protocol.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"Promise | null","links":[{"name":"Promise","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise","start":0,"end":7},{"name":"null","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type","start":10,"end":14}]},"description":""}},"description":"Wait for a drainable writer's backpressure to clear. Returns `null` if\nthe object does not implement the drainable protocol, or a promise that\nfulfills with `true` when the writer can accept more data.\n\n```mjs\nimport { push, ondrain, text } from 'node:stream/iter';\n\nconst { writer, readable } = push({ budget: 16384 });\nconst chunk = new Uint8Array(8192);  // 8 KB\nwriter.writeSync(chunk);\nwriter.writeSync(chunk);  // 16 KB total -- buffer full\n\n// Start consuming so the buffer can actually drain\nconst consuming = text(readable);\n\n// Buffer is full -- wait for drain\nconst canWrite = await ondrain(writer);\nif (canWrite) {\n  await writer.write('c');\n}\nawait writer.end();\nawait consuming;\n```\n\n```cjs\nconst { push, ondrain, text } = require('node:stream/iter');\n\nasync function run() {\n  const { writer, readable } = push({ budget: 16384 });\n  const chunk = new Uint8Array(8192);  // 8 KB\n  writer.writeSync(chunk);\n  writer.writeSync(chunk);  // 16 KB total -- buffer full\n\n  // Start consuming so the buffer can actually drain\n  const consuming = text(readable);\n\n  // Buffer is full -- wait for drain\n  const canWrite = await ondrain(writer);\n  if (canWrite) {\n    await writer.write('c');\n  }\n  await writer.end();\n  await consuming;\n}\n\nrun().catch(console.error);\n```","summary":"Wait for a drainable writer's backpressure to clear. Returns `null` if the object does not implement the drainable protocol, or a promise that fulfills with `true` when the writer can accept more data.","examples":[{"language":"mjs","displayName":null,"code":"import { push, ondrain, text } from 'node:stream/iter';\n\nconst { writer, readable } = push({ budget: 16384 });\nconst chunk = new Uint8Array(8192);  // 8 KB\nwriter.writeSync(chunk);\nwriter.writeSync(chunk);  // 16 KB total -- buffer full\n\n// Start consuming so the buffer can actually drain\nconst consuming = text(readable);\n\n// Buffer is full -- wait for drain\nconst canWrite = await ondrain(writer);\nif (canWrite) {\n  await writer.write('c');\n}\nawait writer.end();\nawait consuming;"},{"language":"cjs","displayName":null,"code":"const { push, ondrain, text } = require('node:stream/iter');\n\nasync function run() {\n  const { writer, readable } = push({ budget: 16384 });\n  const chunk = new Uint8Array(8192);  // 8 KB\n  writer.writeSync(chunk);\n  writer.writeSync(chunk);  // 16 KB total -- buffer full\n\n  // Start consuming so the buffer can actually drain\n  const consuming = text(readable);\n\n  // Buffer is full -- wait for drain\n  const canWrite = await ondrain(writer);\n  if (canWrite) {\n    await writer.write('c');\n  }\n  await writer.end();\n  await consuming;\n}\n\nrun().catch(console.error);"}],"children":[]},{"kind":"method","id":"mergesources-options","name":"merge","title":"`merge(...sources[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"sources","type":{"text":"AsyncIterable | Iterable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13},{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":16,"end":24}]},"description":"whose chunks must be {Uint8Array[]}","default":null,"optional":false,"rest":true,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"AsyncIterable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13}]},"description":"whose chunks fulfill with {Uint8Array[]}"}},"description":"Merge multiple async iterables by yielding batches in temporal order\n(whichever source produces data first). All sources are consumed\nconcurrently.\n\n```mjs\nimport { from, merge, text } from 'node:stream/iter';\n\nconst merged = merge(from('hello '), from('world'));\nconsole.log(await text(merged)); // Order depends on timing\n```\n\n```cjs\nconst { from, merge, text } = require('node:stream/iter');\n\nasync function run() {\n  const merged = merge(from('hello '), from('world'));\n  console.log(await text(merged)); // Order depends on timing\n}\n\nrun().catch(console.error);\n```","summary":"Merge multiple async iterables by yielding batches in temporal order (whichever source produces data first). All sources are consumed concurrently.","examples":[{"language":"mjs","displayName":null,"code":"import { from, merge, text } from 'node:stream/iter';\n\nconst merged = merge(from('hello '), from('world'));\nconsole.log(await text(merged)); // Order depends on timing"},{"language":"cjs","displayName":null,"code":"const { from, merge, text } = require('node:stream/iter');\n\nasync function run() {\n  const merged = merge(from('hello '), from('world'));\n  console.log(await text(merged)); // Order depends on timing\n}\n\nrun().catch(console.error);"}],"children":[]},{"kind":"method","id":"tapcallback","name":"tap","title":"`tap(callback)`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"`(chunks) => void` Called with each batch.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"A stateless transform."}},"description":"Create a pass-through transform that observes batches without modifying them.\nUseful for logging, metrics, or debugging.\n\n```mjs\nimport { from, pull, text, tap } from 'node:stream/iter';\n\nconst result = pull(\n  from('hello'),\n  tap((chunks) => console.log('Batch size:', chunks.length)),\n);\nconsole.log(await text(result));\n```\n\n```cjs\nconst { from, pull, text, tap } = require('node:stream/iter');\n\nasync function run() {\n  const result = pull(\n    from('hello'),\n    tap((chunks) => console.log('Batch size:', chunks.length)),\n  );\n  console.log(await text(result));\n}\n\nrun().catch(console.error);\n```\n\n`tap()` intentionally does not prevent in-place modification of the\nchunks by the tapping callback; but return values are ignored.","summary":"Create a pass-through transform that observes batches without modifying them. Useful for logging, metrics, or debugging.","examples":[{"language":"mjs","displayName":null,"code":"import { from, pull, text, tap } from 'node:stream/iter';\n\nconst result = pull(\n  from('hello'),\n  tap((chunks) => console.log('Batch size:', chunks.length)),\n);\nconsole.log(await text(result));"},{"language":"cjs","displayName":null,"code":"const { from, pull, text, tap } = require('node:stream/iter');\n\nasync function run() {\n  const result = pull(\n    from('hello'),\n    tap((chunks) => console.log('Batch size:', chunks.length)),\n  );\n  console.log(await text(result));\n}\n\nrun().catch(console.error);"}],"children":[]},{"kind":"method","id":"tapsynccallback","name":"tapSync","title":"`tapSync(callback)`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":""}},"description":"Synchronous version of [`tap()`](#tapcallback).","summary":"Synchronous version of `tap()`.","examples":[],"children":[]}]},{"kind":"section","id":"multi-consumer","name":"Multi-consumer","title":"Multi-consumer","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"method","id":"broadcastoptions","name":"broadcast","title":"`broadcast([options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"budget","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Buffer size in bytes. Must be >= 16384.","default":"65536","optional":true,"rest":false,"properties":[]},{"name":"backpressure","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"`'strict'`, `'unbounded'`, `'drop-oldest'`, or\n`'drop-newest'`.","default":"'strict'","optional":true,"rest":false,"properties":[]},{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":""}},"description":"Create a push-model multi-consumer broadcast channel. A single writer pushes\ndata to multiple consumers. Each consumer has an independent cursor into a\nshared buffer.\n\n```mjs\nimport { broadcast, text } from 'node:stream/iter';\n\nconst { writer, broadcast: bc } = broadcast();\n\n// Create consumers before writing\nconst c1 = bc.push();  // Consumer 1\nconst c2 = bc.push();  // Consumer 2\n\n// Producer and consumers must run concurrently. Awaited writes\n// block when the buffer fills until consumers read.\nconst producing = (async () => {\n  await writer.write('hello');\n  await writer.end();\n})();\n\nconst [r1, r2] = await Promise.all([text(c1), text(c2)]);\nconsole.log(r1); // 'hello'\nconsole.log(r2); // 'hello'\nawait producing;\n```\n\n```cjs\nconst { broadcast, text } = require('node:stream/iter');\n\nasync function run() {\n  const { writer, broadcast: bc } = broadcast();\n\n  // Create consumers before writing\n  const c1 = bc.push();  // Consumer 1\n  const c2 = bc.push();  // Consumer 2\n\n  // Producer and consumers must run concurrently. Awaited writes\n  // block when the buffer fills until consumers read.\n  const producing = (async () => {\n    await writer.write('hello');\n    await writer.end();\n  })();\n\n  const [r1, r2] = await Promise.all([text(c1), text(c2)]);\n  console.log(r1); // 'hello'\n  console.log(r2); // 'hello'\n  await producing;\n}\n\nrun().catch(console.error);\n```","summary":"Create a push-model multi-consumer broadcast channel. A single writer pushes data to multiple consumers. Each consumer has an independent cursor into a shared buffer.","examples":[{"language":"mjs","displayName":null,"code":"import { broadcast, text } from 'node:stream/iter';\n\nconst { writer, broadcast: bc } = broadcast();\n\n// Create consumers before writing\nconst c1 = bc.push();  // Consumer 1\nconst c2 = bc.push();  // Consumer 2\n\n// Producer and consumers must run concurrently. Awaited writes\n// block when the buffer fills until consumers read.\nconst producing = (async () => {\n  await writer.write('hello');\n  await writer.end();\n})();\n\nconst [r1, r2] = await Promise.all([text(c1), text(c2)]);\nconsole.log(r1); // 'hello'\nconsole.log(r2); // 'hello'\nawait producing;"},{"language":"cjs","displayName":null,"code":"const { broadcast, text } = require('node:stream/iter');\n\nasync function run() {\n  const { writer, broadcast: bc } = broadcast();\n\n  // Create consumers before writing\n  const c1 = bc.push();  // Consumer 1\n  const c2 = bc.push();  // Consumer 2\n\n  // Producer and consumers must run concurrently. Awaited writes\n  // block when the buffer fills until consumers read.\n  const producing = (async () => {\n    await writer.write('hello');\n    await writer.end();\n  })();\n\n  const [r1, r2] = await Promise.all([text(c1), text(c2)]);\n  console.log(r1); // 'hello'\n  console.log(r2); // 'hello'\n  await producing;\n}\n\nrun().catch(console.error);"}],"children":[{"kind":"method","id":"broadcastcancelreason","name":"cancel","title":"`broadcast.cancel([reason])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"reason","type":{"text":"Error","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Cancel the broadcast. All consumers receive an error.","summary":"Cancel the broadcast. All consumers receive an error.","examples":[],"children":[]},{"kind":"property","id":"broadcastconsumercount","name":"consumerCount","title":"`broadcast.consumerCount`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"The number of active consumers.","summary":"The number of active consumers.","examples":[],"children":[]},{"kind":"method","id":"broadcastpushtransforms-options","name":"push","title":"`broadcast.push([...transforms][, options])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"transforms","type":{"text":"Function | Object","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":11,"end":17}]},"description":"","default":null,"optional":true,"rest":true,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"AsyncIterable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13}]},"description":"whose chunks fulfill with {Uint8Array[]}"}},"description":"Create a new consumer. Each consumer receives all data written to the\nbroadcast from the point of subscription onward. Optional transforms are\napplied to this consumer's view of the data.","summary":"Create a new consumer. Each consumer receives all data written to the broadcast from the point of subscription onward. Optional transforms are applied to this consumer's view of the data.","examples":[],"children":[]},{"kind":"method","id":"broadcastsymboldispose","name":"[Symbol.dispose]","title":"`broadcast[Symbol.dispose]()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Alias for `broadcast.cancel()`.","summary":"Alias for `broadcast.cancel()`.","examples":[],"children":[]}]},{"kind":"method","id":"broadcastfrominput-options","name":"from","title":"`Broadcast.from(input[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"input","type":{"text":"AsyncIterable | Iterable | BroadcastChannel","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13},{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":16,"end":24},{"name":"BroadcastChannel","href":"worker_threads.html#class-broadcastchannel-extends-eventtarget","start":27,"end":43}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"Same as `broadcast()`.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"`{ writer, broadcast }`"}},"description":"Create a {BroadcastChannel} from an existing source. The source is consumed\nautomatically and pushed to all subscribers.","summary":"Create a {BroadcastChannel} from an existing source. The source is consumed automatically and pushed to all subscribers.","examples":[],"children":[]},{"kind":"method","id":"sharesource-options","name":"share","title":"`share(source[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"AsyncIterable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13}]},"description":"The source to share.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"budget","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Buffer size in bytes. Must be >= 16384.","default":"65536","optional":true,"rest":false,"properties":[]},{"name":"backpressure","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"`'strict'`, `'unbounded'`, `'drop-oldest'`, or\n`'drop-newest'`.","default":"'strict'","optional":true,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Share","links":[{"name":"Share","href":"stream_iter.html#class-share","start":0,"end":5}]},"description":""}},"description":"Create a pull-model multi-consumer shared stream. Unlike `broadcast()`, the\nsource is only read when a consumer pulls. Multiple consumers share a single\nbuffer.\n\n```mjs\nimport { from, share, text } from 'node:stream/iter';\n\nconst shared = share(from('hello'));\n\nconst c1 = shared.pull();\nconst c2 = shared.pull();\n\n// Consume concurrently to avoid deadlock with small buffers.\nconst [r1, r2] = await Promise.all([text(c1), text(c2)]);\nconsole.log(r1); // 'hello'\nconsole.log(r2); // 'hello'\n```\n\n```cjs\nconst { from, share, text } = require('node:stream/iter');\n\nasync function run() {\n  const shared = share(from('hello'));\n\n  const c1 = shared.pull();\n  const c2 = shared.pull();\n\n  // Consume concurrently to avoid deadlock with small buffers.\n  const [r1, r2] = await Promise.all([text(c1), text(c2)]);\n  console.log(r1); // 'hello'\n  console.log(r2); // 'hello'\n}\n\nrun().catch(console.error);\n```","summary":"Create a pull-model multi-consumer shared stream. Unlike `broadcast()`, the source is only read when a consumer pulls. Multiple consumers share a single buffer.","examples":[{"language":"mjs","displayName":null,"code":"import { from, share, text } from 'node:stream/iter';\n\nconst shared = share(from('hello'));\n\nconst c1 = shared.pull();\nconst c2 = shared.pull();\n\n// Consume concurrently to avoid deadlock with small buffers.\nconst [r1, r2] = await Promise.all([text(c1), text(c2)]);\nconsole.log(r1); // 'hello'\nconsole.log(r2); // 'hello'"},{"language":"cjs","displayName":null,"code":"const { from, share, text } = require('node:stream/iter');\n\nasync function run() {\n  const shared = share(from('hello'));\n\n  const c1 = shared.pull();\n  const c2 = shared.pull();\n\n  // Consume concurrently to avoid deadlock with small buffers.\n  const [r1, r2] = await Promise.all([text(c1), text(c2)]);\n  console.log(r1); // 'hello'\n  console.log(r2); // 'hello'\n}\n\nrun().catch(console.error);"}],"children":[]},{"kind":"class","id":"class-share","name":"Share","title":"Class: `Share`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":null,"description":"","summary":"","examples":[],"children":[{"kind":"staticMethod","id":"static-method-sharefrominput-options","name":"from","title":"Static method: `Share.from(input[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"input","type":{"text":"AsyncIterable | Shareable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13},{"name":"Shareable","href":"stream_iter.html#interface-shareable","start":16,"end":25}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"Same as `share()`.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"Share","links":[{"name":"Share","href":"stream_iter.html#class-share","start":0,"end":5}]},"description":""}},"description":"Create a {Share} from an existing source.","summary":"Create a {Share} from an existing source.","examples":[],"children":[]},{"kind":"method","id":"sharecancelreason","name":"cancel","title":"`share.cancel([reason])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"reason","type":{"text":"Error","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Cancel the share. All consumers receive an error.","summary":"Cancel the share. All consumers receive an error.","examples":[],"children":[]},{"kind":"property","id":"shareconsumercount","name":"consumerCount","title":"`share.consumerCount`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"The number of active consumers.","summary":"The number of active consumers.","examples":[],"children":[]},{"kind":"method","id":"sharepulltransforms-options","name":"pull","title":"`share.pull([...transforms][, options])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"transforms","type":{"text":"Function | Object","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":11,"end":17}]},"description":"","default":null,"optional":true,"rest":true,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"AsyncIterable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13}]},"description":"whose chunks fulfill with {Uint8Array[]}"}},"description":"Create a new consumer of the shared source.","summary":"Create a new consumer of the shared source.","examples":[],"children":[]},{"kind":"method","id":"sharesymboldispose","name":"[Symbol.dispose]","title":"`share[Symbol.dispose]()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Alias for `share.cancel()`.","summary":"Alias for `share.cancel()`.","examples":[],"children":[]}]},{"kind":"section","id":"interface-shareable","name":"Interface: Shareable","title":"Interface: `Shareable`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"property","id":"sharablesymbolforstreamshareprotocol","name":"[Symbol.for('Stream.shareProtocol')]","title":"`sharable[Symbol.for('Stream.shareProtocol')]`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"default":null,"description":"that returns a {Share}.","summary":"","examples":[],"children":[]}]},{"kind":"section","id":"interface-syncshareable","name":"Interface: SyncShareable","title":"Interface: `SyncShareable`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"property","id":"sharablesymbolforstreamsharesyncprotocol","name":"[Symbol.for('Stream.shareSyncProtocol')]","title":"`sharable[Symbol.for('Stream.shareSyncProtocol')]`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"default":null,"description":"that returns a {SyncShare}.","summary":"","examples":[],"children":[]}]},{"kind":"method","id":"sharesyncsource-options","name":"shareSync","title":"`shareSync(source[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"Iterable","links":[{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":0,"end":8}]},"description":"The sync source to share.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"budget","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Must be >= 16384.","default":"65536","optional":true,"rest":false,"properties":[]},{"name":"backpressure","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":"'strict'","optional":true,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"SyncShare","links":[{"name":"SyncShare","href":"stream_iter.html#class-syncshare","start":0,"end":9}]},"description":""}},"description":"Synchronous version of [`share()`](#sharesource-options).","summary":"Synchronous version of `share()`.","examples":[],"children":[]},{"kind":"class","id":"class-syncshare","name":"SyncShare","title":"Class: `SyncShare`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":null,"description":"","summary":"","examples":[],"children":[{"kind":"staticMethod","id":"static-method-syncsharefromsyncinput-options","name":"fromSync","title":"Static method: `SyncShare.fromSync(input[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"input","type":{"text":"Iterable | SyncShareable","links":[{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":0,"end":8},{"name":"SyncShareable","href":"stream_iter.html#interface-syncshareable","start":11,"end":24}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"SyncShare","links":[{"name":"SyncShare","href":"stream_iter.html#class-syncshare","start":0,"end":9}]},"description":""}},"description":"","summary":"","examples":[],"children":[]},{"kind":"property","id":"sharebuffersize","name":"bufferSize","title":"`share.bufferSize`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"The number of chunks currently buffered.","summary":"The number of chunks currently buffered.","examples":[],"children":[]},{"kind":"method","id":"sharecancelreason-1","name":"cancel","title":"`share.cancel([reason])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"reason","type":{"text":"Error","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Cancel the share. All consumers receive an error.","summary":"Cancel the share. All consumers receive an error.","examples":[],"children":[]},{"kind":"property","id":"shareconsumercount-1","name":"consumerCount","title":"`share.consumerCount`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"The number of active consumers.","summary":"The number of active consumers.","examples":[],"children":[]},{"kind":"method","id":"sharepulltransforms-options-1","name":"pull","title":"`share.pull([...transforms][, options])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"transforms","type":{"text":"Function | Object","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":11,"end":17}]},"description":"","default":null,"optional":true,"rest":true,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Iterable","links":[{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":0,"end":8}]},"description":"whose chunks return {Uint8Array[]}"}},"description":"Create a new consumer of the shared source.","summary":"Create a new consumer of the shared source.","examples":[],"children":[]},{"kind":"method","id":"sharesymboldispose-1","name":"[Symbol.dispose]","title":"`share[Symbol.dispose]()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Alias for `share.cancel()`.","summary":"Alias for `share.cancel()`.","examples":[],"children":[]}]}]},{"kind":"section","id":"compression-and-decompression-transforms","name":"Compression and decompression transforms","title":"Compression and decompression transforms","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Compression and decompression transforms for use with `pull()`, `pullSync()`,\n`pipeTo()`, and `pipeToSync()` are available via the [`node:zlib/iter`](zlib.html#iterable-compression)\nmodule. See the [`node:zlib/iter` documentation](zlib.html#iterable-compression) for details.","summary":"Compression and decompression transforms for use with `pull()`, `pullSync()`, `pipeTo()`, and `pipeToSync()` are available via the `node:zlib/iter` module. See the `node:zlib/iter` documentation for details.","examples":[],"children":[]},{"kind":"section","id":"classic-stream-interop","name":"Classic stream interop","title":"Classic stream interop","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"These utility functions bridge between classic\n[`stream.Readable`](stream.html#class-streamreadable)/[`stream.Writable`](stream.html#class-streamwritable) streams and the `stream/iter`\nAPI.\n\nBoth `fromReadable()` and `fromWritable()` accept duck-typed objects -- they\ndo not require the input to extend `stream.Readable` or `stream.Writable`\ndirectly. The minimum contract is described below for each function.","summary":"These utility functions bridge between classic `stream.Readable`/`stream.Writable` streams and the `stream/iter` API.","examples":[],"children":[{"kind":"method","id":"fromreadablereadable","name":"fromReadable","title":"`fromReadable(readable)`","scope":"module","overloadOf":null,"stability":{"index":"1","description":"Experimental"},"added":["v26.1.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"readable","type":{"text":"stream.Readable | Object","links":[{"name":"stream.Readable","href":"stream.html#class-streamreadable","start":0,"end":15},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":18,"end":24}]},"description":"A classic Readable stream or any object\nwith `read()`, `on()`, and `off()` methods.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"AsyncIterable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13}]},"description":"whose chunks fulfill with {Uint8Array[]}"}},"description":"Converts a classic Readable stream (or duck-typed equivalent) into a\nstream/iter async iterable source that can be passed to [`from()`](#frominput),\n[`pull()`](#pullsource-transforms-options), [`text()`](#textsource-options), etc.\n\nIf the object implements the [`toAsyncStreamable`](#streamtoasyncstreamable) protocol (as\n`stream.Readable` does), that protocol is used. Otherwise, the function\nduck-types on `read()`, `on()`, and `off()` (EventEmitter) and wraps the\nstream with a batched async iterator.\n\nThe result is cached per instance -- calling `fromReadable()` twice with the\nsame stream returns the same iterable.\n\nFor object-mode or encoded Readable streams, chunks are automatically\nnormalized to `Uint8Array`.\n\n```mjs\nimport { Readable } from 'node:stream';\nimport { fromReadable, text } from 'node:stream/iter';\n\nconst readable = new Readable({\n  read() { this.push('hello world'); this.push(null); },\n});\n\nconst result = await text(fromReadable(readable));\nconsole.log(result); // 'hello world'\n```\n\n```cjs\nconst { Readable } = require('node:stream');\nconst { fromReadable, text } = require('node:stream/iter');\n\nconst readable = new Readable({\n  read() { this.push('hello world'); this.push(null); },\n});\n\nasync function run() {\n  const result = await text(fromReadable(readable));\n  console.log(result); // 'hello world'\n}\nrun();\n```","summary":"Converts a classic Readable stream (or duck-typed equivalent) into a stream/iter async iterable source that can be passed to `from()`, `pull()`, `text()`, etc.","examples":[{"language":"mjs","displayName":null,"code":"import { Readable } from 'node:stream';\nimport { fromReadable, text } from 'node:stream/iter';\n\nconst readable = new Readable({\n  read() { this.push('hello world'); this.push(null); },\n});\n\nconst result = await text(fromReadable(readable));\nconsole.log(result); // 'hello world'"},{"language":"cjs","displayName":null,"code":"const { Readable } = require('node:stream');\nconst { fromReadable, text } = require('node:stream/iter');\n\nconst readable = new Readable({\n  read() { this.push('hello world'); this.push(null); },\n});\n\nasync function run() {\n  const result = await text(fromReadable(readable));\n  console.log(result); // 'hello world'\n}\nrun();"}],"children":[]},{"kind":"method","id":"fromwritablewritable-options","name":"fromWritable","title":"`fromWritable(writable[, options])`","scope":"module","overloadOf":null,"stability":{"index":"1","description":"Experimental"},"added":["v26.1.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"writable","type":{"text":"stream.Writable | Object","links":[{"name":"stream.Writable","href":"stream.html#class-streamwritable","start":0,"end":15},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":18,"end":24}]},"description":"A classic Writable stream or any object\nwith `write()` and `on()` methods.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"backpressure","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Backpressure policy.","default":"'strict'","optional":true,"rest":false,"properties":[{"name":"'strict'","type":null,"description":"writes are rejected when the buffer is full. Catches\ncallers that ignore backpressure.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"'unbounded'","type":null,"description":"writes wait for drain when the buffer is full. Recommended\nfor use with [`pipeTo()`](#pipetosource-transforms-writer-options).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"'drop-newest'","type":null,"description":"writes are silently discarded when the buffer is full.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"'drop-oldest'","type":null,"description":"**not supported**. Throws `ERR_INVALID_ARG_VALUE`.","default":null,"optional":false,"rest":false,"properties":[]}]}]}],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"A stream/iter Writer adapter."}},"description":"Creates a stream/iter Writer adapter from a classic Writable stream (or\nduck-typed equivalent). The adapter can be passed to [`pipeTo()`](#pipetosource-transforms-writer-options) as a\ndestination.\n\nSince all writes on a classic Writable are fundamentally asynchronous,\nthe synchronous Writer methods (`writeSync`, `writevSync`, `endSync`) always\nreturn `false` or `-1`, deferring to the async path. The per-write\n`options.signal` parameter from the Writer interface is also ignored.\n\nThe result is cached per instance and backpressure policy -- calling\n`fromWritable()` twice with the same stream and `backpressure` option returns\nthe same Writer.\n\nFor duck-typed streams that do not expose `writableHighWaterMark`,\n`writableLength`, or similar properties, sensible defaults are used.\nObject-mode writables (if detectable) are rejected since the Writer\ninterface is bytes-only.\n\n```mjs\nimport { Writable } from 'node:stream';\nimport { from, fromWritable, pipeTo } from 'node:stream/iter';\n\nconst writable = new Writable({\n  write(chunk, encoding, cb) { console.log(chunk.toString()); cb(); },\n});\n\nawait pipeTo(from('hello world'),\n             fromWritable(writable, { backpressure: 'unbounded' }));\n```\n\n```cjs\nconst { Writable } = require('node:stream');\nconst { from, fromWritable, pipeTo } = require('node:stream/iter');\n\nasync function run() {\n  const writable = new Writable({\n    write(chunk, encoding, cb) { console.log(chunk.toString()); cb(); },\n  });\n\n  await pipeTo(from('hello world'),\n               fromWritable(writable, { backpressure: 'unbounded' }));\n}\nrun();\n```","summary":"Creates a stream/iter Writer adapter from a classic Writable stream (or duck-typed equivalent). The adapter can be passed to `pipeTo()` as a destination.","examples":[{"language":"mjs","displayName":null,"code":"import { Writable } from 'node:stream';\nimport { from, fromWritable, pipeTo } from 'node:stream/iter';\n\nconst writable = new Writable({\n  write(chunk, encoding, cb) { console.log(chunk.toString()); cb(); },\n});\n\nawait pipeTo(from('hello world'),\n             fromWritable(writable, { backpressure: 'unbounded' }));"},{"language":"cjs","displayName":null,"code":"const { Writable } = require('node:stream');\nconst { from, fromWritable, pipeTo } = require('node:stream/iter');\n\nasync function run() {\n  const writable = new Writable({\n    write(chunk, encoding, cb) { console.log(chunk.toString()); cb(); },\n  });\n\n  await pipeTo(from('hello world'),\n               fromWritable(writable, { backpressure: 'unbounded' }));\n}\nrun();"}],"children":[]},{"kind":"method","id":"toreadablesource-options","name":"toReadable","title":"`toReadable(source[, options])`","scope":"module","overloadOf":null,"stability":{"index":"1","description":"Experimental"},"added":["v26.1.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"AsyncIterable","links":[{"name":"AsyncIterable","href":"https://tc39.github.io/ecma262/#sec-asynciterable-interface","start":0,"end":13}]},"description":"whose chunks must fulfill with {Uint8Array[]}\nthe return value of [`pull()`](#pullsource-transforms-options) or [`from()`](#frominput).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"highWaterMark","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The internal buffer size in bytes before\nbackpressure is applied.","default":"`65536` (64 KB)","optional":true,"rest":false,"properties":[]},{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"An optional signal to abort the readable.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"stream.Readable","links":[{"name":"stream.Readable","href":"stream.html#class-streamreadable","start":0,"end":15}]},"description":""}},"description":"Creates a byte-mode [`stream.Readable`](stream.html#class-streamreadable) from the `source`\n(the native batch format used by the stream/iter API). Each `Uint8Array` in a\nyielded batch is pushed as a separate chunk into the Readable.\n\n```mjs\nimport { createWriteStream } from 'node:fs';\nimport { from, pull, toReadable } from 'node:stream/iter';\nimport { compressGzip } from 'node:zlib/iter';\n\nconst source = pull(from('hello world'), compressGzip());\nconst readable = toReadable(source);\n\nreadable.pipe(createWriteStream('output.gz'));\n```\n\n```cjs\nconst { createWriteStream } = require('node:fs');\nconst { from, pull, toReadable } = require('node:stream/iter');\nconst { compressGzip } = require('node:zlib/iter');\n\nconst source = pull(from('hello world'), compressGzip());\nconst readable = toReadable(source);\n\nreadable.pipe(createWriteStream('output.gz'));\n```","summary":"Creates a byte-mode `stream.Readable` from the `source` (the native batch format used by the stream/iter API). Each `Uint8Array` in a yielded batch is pushed as a separate chunk into the Readable.","examples":[{"language":"mjs","displayName":null,"code":"import { createWriteStream } from 'node:fs';\nimport { from, pull, toReadable } from 'node:stream/iter';\nimport { compressGzip } from 'node:zlib/iter';\n\nconst source = pull(from('hello world'), compressGzip());\nconst readable = toReadable(source);\n\nreadable.pipe(createWriteStream('output.gz'));"},{"language":"cjs","displayName":null,"code":"const { createWriteStream } = require('node:fs');\nconst { from, pull, toReadable } = require('node:stream/iter');\nconst { compressGzip } = require('node:zlib/iter');\n\nconst source = pull(from('hello world'), compressGzip());\nconst readable = toReadable(source);\n\nreadable.pipe(createWriteStream('output.gz'));"}],"children":[]},{"kind":"method","id":"toreadablesyncsource-options","name":"toReadableSync","title":"`toReadableSync(source[, options])`","scope":"module","overloadOf":null,"stability":{"index":"1","description":"Experimental"},"added":["v26.1.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"source","type":{"text":"Iterable","links":[{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":0,"end":8}]},"description":"whose chunks must return {Uint8Array[]}, such as the\nreturn value of [`pullSync()`](#pullsyncsource-transforms) or [`fromSync()`](#fromsyncinput).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"highWaterMark","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The internal buffer size in bytes before\nbackpressure is applied.","default":"`65536` (64 KB)","optional":true,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"stream.Readable","links":[{"name":"stream.Readable","href":"stream.html#class-streamreadable","start":0,"end":15}]},"description":""}},"description":"Creates a byte-mode [`stream.Readable`](stream.html#class-streamreadable) from the `source`.\nThe `_read()` method pulls from the iterator\nsynchronously, so data is available immediately via `readable.read()`.\n\n```mjs\nimport { fromSync, toReadableSync } from 'node:stream/iter';\n\nconst source = fromSync('hello world');\nconst readable = toReadableSync(source);\n\nconsole.log(readable.read().toString()); // 'hello world'\n```\n\n```cjs\nconst { fromSync, toReadableSync } = require('node:stream/iter');\n\nconst source = fromSync('hello world');\nconst readable = toReadableSync(source);\n\nconsole.log(readable.read().toString()); // 'hello world'\n```","summary":"Creates a byte-mode `stream.Readable` from the `source`. The `_read()` method pulls from the iterator synchronously, so data is available immediately via `readable.read()`.","examples":[{"language":"mjs","displayName":null,"code":"import { fromSync, toReadableSync } from 'node:stream/iter';\n\nconst source = fromSync('hello world');\nconst readable = toReadableSync(source);\n\nconsole.log(readable.read().toString()); // 'hello world'"},{"language":"cjs","displayName":null,"code":"const { fromSync, toReadableSync } = require('node:stream/iter');\n\nconst source = fromSync('hello world');\nconst readable = toReadableSync(source);\n\nconsole.log(readable.read().toString()); // 'hello world'"}],"children":[]},{"kind":"method","id":"towritablewriter","name":"toWritable","title":"`toWritable(writer)`","scope":"module","overloadOf":null,"stability":{"index":"1","description":"Experimental"},"added":["v26.1.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"writer","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"A stream/iter Writer. Only the `write()` method is\nrequired; `end()`, `fail()`, `writeSync()`, `writevSync()`, `endSync()`,\nand `writev()` are optional.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"stream.Writable","links":[{"name":"stream.Writable","href":"stream.html#class-streamwritable","start":0,"end":15}]},"description":""}},"description":"Creates a classic [`stream.Writable`](stream.html#class-streamwritable) backed by a stream/iter Writer.\n\nEach `_write()` / `_writev()` call attempts the Writer's synchronous method\nfirst (`writeSync` / `writevSync`), falling back to the async method if the\nsync path returns `false`. Similarly, `_final()` tries `endSync()`\nbefore `end()`. When the sync path succeeds, the callback is deferred via\n`queueMicrotask` to preserve the async resolution contract.\n\nThe Writable's `highWaterMark` is set to `Number.MAX_SAFE_INTEGER` to\neffectively disable its internal buffering, allowing the underlying Writer\nto manage backpressure directly.\n\n```mjs\nimport { push, toWritable } from 'node:stream/iter';\n\nconst { writer, readable } = push();\nconst writable = toWritable(writer);\n\nwritable.write('hello');\nwritable.end();\n```\n\n```cjs\nconst { push, toWritable } = require('node:stream/iter');\n\nconst { writer, readable } = push();\nconst writable = toWritable(writer);\n\nwritable.write('hello');\nwritable.end();\n```","summary":"Creates a classic `stream.Writable` backed by a stream/iter Writer.","examples":[{"language":"mjs","displayName":null,"code":"import { push, toWritable } from 'node:stream/iter';\n\nconst { writer, readable } = push();\nconst writable = toWritable(writer);\n\nwritable.write('hello');\nwritable.end();"},{"language":"cjs","displayName":null,"code":"const { push, toWritable } = require('node:stream/iter');\n\nconst { writer, readable } = push();\nconst writable = toWritable(writer);\n\nwritable.write('hello');\nwritable.end();"}],"children":[]}]},{"kind":"section","id":"protocol-symbols","name":"Protocol symbols","title":"Protocol symbols","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"These well-known symbols allow third-party objects to participate in the\nstreaming protocol without importing from `node:stream/iter` directly.","summary":"These well-known symbols allow third-party objects to participate in the streaming protocol without importing from `node:stream/iter` directly.","examples":[],"children":[{"kind":"property","id":"streambroadcastprotocol","name":"broadcastProtocol","title":"`Stream.broadcastProtocol`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"* Value: `Symbol.for('Stream.broadcastProtocol')`\n\nThe value must be a function. When called by `Broadcast.from()`, it receives\nthe options passed to `Broadcast.from()` and must return an object conforming\nto the {BroadcastChannel} interface. The implementation is fully custom -- it can\nmanage consumers, buffering, and backpressure however it wants.\n\n```mjs\nimport { Broadcast, text } from 'node:stream/iter';\n\n// This example defers to the built-in Broadcast, but a custom\n// implementation could use any mechanism.\nclass MessageBus {\n  #broadcast;\n  #writer;\n\n  constructor() {\n    const { writer, broadcast } = Broadcast();\n    this.#writer = writer;\n    this.#broadcast = broadcast;\n  }\n\n  [Symbol.for('Stream.broadcastProtocol')](options) {\n    return this.#broadcast;\n  }\n\n  send(data) {\n    this.#writer.write(new TextEncoder().encode(data));\n  }\n\n  close() {\n    this.#writer.end();\n  }\n}\n\nconst bus = new MessageBus();\nconst { broadcast } = Broadcast.from(bus);\nconst consumer = broadcast.push();\nbus.send('hello');\nbus.close();\nconsole.log(await text(consumer)); // 'hello'\n```\n\n```cjs\nconst { Broadcast, text } = require('node:stream/iter');\n\n// This example defers to the built-in Broadcast, but a custom\n// implementation could use any mechanism.\nclass MessageBus {\n  #broadcast;\n  #writer;\n\n  constructor() {\n    const { writer, broadcast } = Broadcast();\n    this.#writer = writer;\n    this.#broadcast = broadcast;\n  }\n\n  [Symbol.for('Stream.broadcastProtocol')](options) {\n    return this.#broadcast;\n  }\n\n  send(data) {\n    this.#writer.write(new TextEncoder().encode(data));\n  }\n\n  close() {\n    this.#writer.end();\n  }\n}\n\nconst bus = new MessageBus();\nconst { broadcast } = Broadcast.from(bus);\nconst consumer = broadcast.push();\nbus.send('hello');\nbus.close();\ntext(consumer).then(console.log); // 'hello'\n```","summary":"The value must be a function. When called by `Broadcast.from()`, it receives the options passed to `Broadcast.from()` and must return an object conforming to the {BroadcastChannel} interface. The implementation is fully custom -- it can manage consumers, buffering, and backpressure however it wants.","examples":[{"language":"mjs","displayName":null,"code":"import { Broadcast, text } from 'node:stream/iter';\n\n// This example defers to the built-in Broadcast, but a custom\n// implementation could use any mechanism.\nclass MessageBus {\n  #broadcast;\n  #writer;\n\n  constructor() {\n    const { writer, broadcast } = Broadcast();\n    this.#writer = writer;\n    this.#broadcast = broadcast;\n  }\n\n  [Symbol.for('Stream.broadcastProtocol')](options) {\n    return this.#broadcast;\n  }\n\n  send(data) {\n    this.#writer.write(new TextEncoder().encode(data));\n  }\n\n  close() {\n    this.#writer.end();\n  }\n}\n\nconst bus = new MessageBus();\nconst { broadcast } = Broadcast.from(bus);\nconst consumer = broadcast.push();\nbus.send('hello');\nbus.close();\nconsole.log(await text(consumer)); // 'hello'"},{"language":"cjs","displayName":null,"code":"const { Broadcast, text } = require('node:stream/iter');\n\n// This example defers to the built-in Broadcast, but a custom\n// implementation could use any mechanism.\nclass MessageBus {\n  #broadcast;\n  #writer;\n\n  constructor() {\n    const { writer, broadcast } = Broadcast();\n    this.#writer = writer;\n    this.#broadcast = broadcast;\n  }\n\n  [Symbol.for('Stream.broadcastProtocol')](options) {\n    return this.#broadcast;\n  }\n\n  send(data) {\n    this.#writer.write(new TextEncoder().encode(data));\n  }\n\n  close() {\n    this.#writer.end();\n  }\n}\n\nconst bus = new MessageBus();\nconst { broadcast } = Broadcast.from(bus);\nconst consumer = broadcast.push();\nbus.send('hello');\nbus.close();\ntext(consumer).then(console.log); // 'hello'"}],"children":[]},{"kind":"property","id":"streamdrainableprotocol","name":"drainableProtocol","title":"`Stream.drainableProtocol`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"* Value: `Symbol.for('Stream.drainableProtocol')`\n\nImplement to make a writer compatible with `ondrain()`. The method should\nreturn `null` if no backpressure, or a promise that fulfills with a truthy value\nwhen backpressure clears.\n\n```mjs\nimport { ondrain } from 'node:stream/iter';\n\nclass CustomWriter {\n  #queue = [];\n  #drain = null;\n  #closed = false;\n  [Symbol.for('Stream.drainableProtocol')]() {\n    if (this.#closed) return null;\n    if (this.#queue.length < 3) return Promise.resolve(true);\n    this.#drain ??= Promise.withResolvers();\n    return this.#drain.promise;\n  }\n  write(chunk) {\n    this.#queue.push(chunk);\n  }\n  flush() {\n    this.#queue.length = 0;\n    this.#drain?.resolve(true);\n    this.#drain = null;\n  }\n  close() {\n    this.#closed = true;\n  }\n}\nconst writer = new CustomWriter();\nconst ready = ondrain(writer);\nconsole.log(ready); // Promise { true } -- no backpressure\n```\n\n```cjs\nconst { ondrain } = require('node:stream/iter');\n\nclass CustomWriter {\n  #queue = [];\n  #drain = null;\n  #closed = false;\n\n  [Symbol.for('Stream.drainableProtocol')]() {\n    if (this.#closed) return null;\n    if (this.#queue.length < 3) return Promise.resolve(true);\n    this.#drain ??= Promise.withResolvers();\n    return this.#drain.promise;\n  }\n\n  write(chunk) {\n    this.#queue.push(chunk);\n  }\n\n  flush() {\n    this.#queue.length = 0;\n    this.#drain?.resolve(true);\n    this.#drain = null;\n  }\n\n  close() {\n    this.#closed = true;\n  }\n}\n\nconst writer = new CustomWriter();\nconst ready = ondrain(writer);\nconsole.log(ready); // Promise { true } -- no backpressure\n```","summary":"Implement to make a writer compatible with `ondrain()`. The method should return `null` if no backpressure, or a promise that fulfills with a truthy value when backpressure clears.","examples":[{"language":"mjs","displayName":null,"code":"import { ondrain } from 'node:stream/iter';\n\nclass CustomWriter {\n  #queue = [];\n  #drain = null;\n  #closed = false;\n  [Symbol.for('Stream.drainableProtocol')]() {\n    if (this.#closed) return null;\n    if (this.#queue.length < 3) return Promise.resolve(true);\n    this.#drain ??= Promise.withResolvers();\n    return this.#drain.promise;\n  }\n  write(chunk) {\n    this.#queue.push(chunk);\n  }\n  flush() {\n    this.#queue.length = 0;\n    this.#drain?.resolve(true);\n    this.#drain = null;\n  }\n  close() {\n    this.#closed = true;\n  }\n}\nconst writer = new CustomWriter();\nconst ready = ondrain(writer);\nconsole.log(ready); // Promise { true } -- no backpressure"},{"language":"cjs","displayName":null,"code":"const { ondrain } = require('node:stream/iter');\n\nclass CustomWriter {\n  #queue = [];\n  #drain = null;\n  #closed = false;\n\n  [Symbol.for('Stream.drainableProtocol')]() {\n    if (this.#closed) return null;\n    if (this.#queue.length < 3) return Promise.resolve(true);\n    this.#drain ??= Promise.withResolvers();\n    return this.#drain.promise;\n  }\n\n  write(chunk) {\n    this.#queue.push(chunk);\n  }\n\n  flush() {\n    this.#queue.length = 0;\n    this.#drain?.resolve(true);\n    this.#drain = null;\n  }\n\n  close() {\n    this.#closed = true;\n  }\n}\n\nconst writer = new CustomWriter();\nconst ready = ondrain(writer);\nconsole.log(ready); // Promise { true } -- no backpressure"}],"children":[]},{"kind":"property","id":"streamshareprotocol","name":"shareProtocol","title":"`Stream.shareProtocol`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"* Value: `Symbol.for('Stream.shareProtocol')`\n\nThe value must be a function. When called by `Share.from()`, it receives the\noptions passed to `Share.from()` and must return an object conforming to the\n{Share} interface. The implementation is fully custom -- it can manage the shared\nsource, consumers, buffering, and backpressure however it wants.\n\n```mjs\nimport { share, Share, text } from 'node:stream/iter';\n\n// This example defers to the built-in share(), but a custom\n// implementation could use any mechanism.\nclass DataPool {\n  #share;\n\n  constructor(source) {\n    this.#share = share(source);\n  }\n\n  [Symbol.for('Stream.shareProtocol')](options) {\n    return this.#share;\n  }\n}\n\nconst pool = new DataPool(\n  (async function* () {\n    yield 'hello';\n  })(),\n);\n\nconst shared = Share.from(pool);\nconst consumer = shared.pull();\nconsole.log(await text(consumer)); // 'hello'\n```\n\n```cjs\nconst { share, Share, text } = require('node:stream/iter');\n\n// This example defers to the built-in share(), but a custom\n// implementation could use any mechanism.\nclass DataPool {\n  #share;\n\n  constructor(source) {\n    this.#share = share(source);\n  }\n\n  [Symbol.for('Stream.shareProtocol')](options) {\n    return this.#share;\n  }\n}\n\nconst pool = new DataPool(\n  (async function* () {\n    yield 'hello';\n  })(),\n);\n\nconst shared = Share.from(pool);\nconst consumer = shared.pull();\ntext(consumer).then(console.log); // 'hello'\n```","summary":"The value must be a function. When called by `Share.from()`, it receives the options passed to `Share.from()` and must return an object conforming to the {Share} interface. The implementation is fully custom -- it can manage the shared source, consumers, buffering, and backpressure however it wants.","examples":[{"language":"mjs","displayName":null,"code":"import { share, Share, text } from 'node:stream/iter';\n\n// This example defers to the built-in share(), but a custom\n// implementation could use any mechanism.\nclass DataPool {\n  #share;\n\n  constructor(source) {\n    this.#share = share(source);\n  }\n\n  [Symbol.for('Stream.shareProtocol')](options) {\n    return this.#share;\n  }\n}\n\nconst pool = new DataPool(\n  (async function* () {\n    yield 'hello';\n  })(),\n);\n\nconst shared = Share.from(pool);\nconst consumer = shared.pull();\nconsole.log(await text(consumer)); // 'hello'"},{"language":"cjs","displayName":null,"code":"const { share, Share, text } = require('node:stream/iter');\n\n// This example defers to the built-in share(), but a custom\n// implementation could use any mechanism.\nclass DataPool {\n  #share;\n\n  constructor(source) {\n    this.#share = share(source);\n  }\n\n  [Symbol.for('Stream.shareProtocol')](options) {\n    return this.#share;\n  }\n}\n\nconst pool = new DataPool(\n  (async function* () {\n    yield 'hello';\n  })(),\n);\n\nconst shared = Share.from(pool);\nconst consumer = shared.pull();\ntext(consumer).then(console.log); // 'hello'"}],"children":[]},{"kind":"property","id":"streamsharesyncprotocol","name":"shareSyncProtocol","title":"`Stream.shareSyncProtocol`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"* Value: `Symbol.for('Stream.shareSyncProtocol')`\n\nThe value must be a function. When called by `SyncShare.fromSync()`, it receives\nthe options passed to `SyncShare.fromSync()` and must return an object conforming\nto the {SyncShare} interface. The implementation is fully custom -- it can manage\nthe shared source, consumers, and buffering however it wants.\n\n```mjs\nimport { shareSync, SyncShare, textSync } from 'node:stream/iter';\n\n// This example defers to the built-in shareSync(), but a custom\n// implementation could use any mechanism.\nclass SyncDataPool {\n  #share;\n\n  constructor(source) {\n    this.#share = shareSync(source);\n  }\n\n  [Symbol.for('Stream.shareSyncProtocol')](options) {\n    return this.#share;\n  }\n}\n\nconst encoder = new TextEncoder();\nconst pool = new SyncDataPool(\n  function* () {\n    yield [encoder.encode('hello')];\n  }(),\n);\n\nconst shared = SyncShare.fromSync(pool);\nconst consumer = shared.pull();\nconsole.log(textSync(consumer)); // 'hello'\n```\n\n```cjs\nconst { shareSync, SyncShare, textSync } = require('node:stream/iter');\n\n// This example defers to the built-in shareSync(), but a custom\n// implementation could use any mechanism.\nclass SyncDataPool {\n  #share;\n\n  constructor(source) {\n    this.#share = shareSync(source);\n  }\n\n  [Symbol.for('Stream.shareSyncProtocol')](options) {\n    return this.#share;\n  }\n}\n\nconst encoder = new TextEncoder();\nconst pool = new SyncDataPool(\n  function* () {\n    yield [encoder.encode('hello')];\n  }(),\n);\n\nconst shared = SyncShare.fromSync(pool);\nconst consumer = shared.pull();\nconsole.log(textSync(consumer)); // 'hello'\n```","summary":"The value must be a function. When called by `SyncShare.fromSync()`, it receives the options passed to `SyncShare.fromSync()` and must return an object conforming to the {SyncShare} interface. The implementation is fully custom -- it can manage the shared source, consumers, and buffering however it wants.","examples":[{"language":"mjs","displayName":null,"code":"import { shareSync, SyncShare, textSync } from 'node:stream/iter';\n\n// This example defers to the built-in shareSync(), but a custom\n// implementation could use any mechanism.\nclass SyncDataPool {\n  #share;\n\n  constructor(source) {\n    this.#share = shareSync(source);\n  }\n\n  [Symbol.for('Stream.shareSyncProtocol')](options) {\n    return this.#share;\n  }\n}\n\nconst encoder = new TextEncoder();\nconst pool = new SyncDataPool(\n  function* () {\n    yield [encoder.encode('hello')];\n  }(),\n);\n\nconst shared = SyncShare.fromSync(pool);\nconst consumer = shared.pull();\nconsole.log(textSync(consumer)); // 'hello'"},{"language":"cjs","displayName":null,"code":"const { shareSync, SyncShare, textSync } = require('node:stream/iter');\n\n// This example defers to the built-in shareSync(), but a custom\n// implementation could use any mechanism.\nclass SyncDataPool {\n  #share;\n\n  constructor(source) {\n    this.#share = shareSync(source);\n  }\n\n  [Symbol.for('Stream.shareSyncProtocol')](options) {\n    return this.#share;\n  }\n}\n\nconst encoder = new TextEncoder();\nconst pool = new SyncDataPool(\n  function* () {\n    yield [encoder.encode('hello')];\n  }(),\n);\n\nconst shared = SyncShare.fromSync(pool);\nconst consumer = shared.pull();\nconsole.log(textSync(consumer)); // 'hello'"}],"children":[]},{"kind":"property","id":"streamtoasyncstreamable","name":"toAsyncStreamable","title":"`Stream.toAsyncStreamable`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"* Value: `Symbol.for('Stream.toAsyncStreamable')`\n\nThe value must be a function that converts the object into a streamable value.\nWhen the object is encountered anywhere in the streaming pipeline (as a source\npassed to `from()`, or as a value returned from a transform), this method is\ncalled to produce the actual data. It may return any value that resolves to:\na string, `Uint8Array`, `AsyncIterable`, `Iterable`, or another streamable\nobject.\n\n```mjs\nimport { from, text } from 'node:stream/iter';\n\nclass Greeting {\n  #name;\n\n  constructor(name) {\n    this.#name = name;\n  }\n\n  [Symbol.for('Stream.toAsyncStreamable')]() {\n    return `hello ${this.#name}`;\n  }\n}\n\nconst stream = from(new Greeting('world'));\nconsole.log(await text(stream)); // 'hello world'\n```\n\n```cjs\nconst { from, text } = require('node:stream/iter');\n\nclass Greeting {\n  #name;\n\n  constructor(name) {\n    this.#name = name;\n  }\n\n  [Symbol.for('Stream.toAsyncStreamable')]() {\n    return `hello ${this.#name}`;\n  }\n}\n\nconst stream = from(new Greeting('world'));\ntext(stream).then(console.log); // 'hello world'\n```","summary":"The value must be a function that converts the object into a streamable value. When the object is encountered anywhere in the streaming pipeline (as a source passed to `from()`, or as a value returned from a transform), this method is called to produce the actual data. It may return any value that resolves to: a string, `Uint8Array`, `AsyncIterable`, `Iterable`, or another streamable object.","examples":[{"language":"mjs","displayName":null,"code":"import { from, text } from 'node:stream/iter';\n\nclass Greeting {\n  #name;\n\n  constructor(name) {\n    this.#name = name;\n  }\n\n  [Symbol.for('Stream.toAsyncStreamable')]() {\n    return `hello ${this.#name}`;\n  }\n}\n\nconst stream = from(new Greeting('world'));\nconsole.log(await text(stream)); // 'hello world'"},{"language":"cjs","displayName":null,"code":"const { from, text } = require('node:stream/iter');\n\nclass Greeting {\n  #name;\n\n  constructor(name) {\n    this.#name = name;\n  }\n\n  [Symbol.for('Stream.toAsyncStreamable')]() {\n    return `hello ${this.#name}`;\n  }\n}\n\nconst stream = from(new Greeting('world'));\ntext(stream).then(console.log); // 'hello world'"}],"children":[]},{"kind":"property","id":"streamtostreamable","name":"toStreamable","title":"`Stream.toStreamable`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"* Value: `Symbol.for('Stream.toStreamable')`\n\nThe value must be a function that synchronously converts the object into a\nstreamable value. When the object is encountered anywhere in the streaming\npipeline (as a source passed to `fromSync()`, or as a value returned from a\nsync transform), this method is called to produce the actual data. It must\nsynchronously return a streamable value: a string, `Uint8Array`, or `Iterable`.\n\n```mjs\nimport { fromSync, textSync } from 'node:stream/iter';\n\nclass Greeting {\n  #name;\n\n  constructor(name) {\n    this.#name = name;\n  }\n\n  [Symbol.for('Stream.toStreamable')]() {\n    return `hello ${this.#name}`;\n  }\n}\n\nconst stream = fromSync(new Greeting('world'));\nconsole.log(textSync(stream)); // 'hello world'\n```\n\n```cjs\nconst { fromSync, textSync } = require('node:stream/iter');\n\nclass Greeting {\n  #name;\n\n  constructor(name) {\n    this.#name = name;\n  }\n\n  [Symbol.for('Stream.toStreamable')]() {\n    return `hello ${this.#name}`;\n  }\n}\n\nconst stream = fromSync(new Greeting('world'));\nconsole.log(textSync(stream)); // 'hello world'\n```","summary":"The value must be a function that synchronously converts the object into a streamable value. When the object is encountered anywhere in the streaming pipeline (as a source passed to `fromSync()`, or as a value returned from a sync transform), this method is called to produce the actual data. It must synchronously return a streamable value: a string, `Uint8Array`, or `Iterable`.","examples":[{"language":"mjs","displayName":null,"code":"import { fromSync, textSync } from 'node:stream/iter';\n\nclass Greeting {\n  #name;\n\n  constructor(name) {\n    this.#name = name;\n  }\n\n  [Symbol.for('Stream.toStreamable')]() {\n    return `hello ${this.#name}`;\n  }\n}\n\nconst stream = fromSync(new Greeting('world'));\nconsole.log(textSync(stream)); // 'hello world'"},{"language":"cjs","displayName":null,"code":"const { fromSync, textSync } = require('node:stream/iter');\n\nclass Greeting {\n  #name;\n\n  constructor(name) {\n    this.#name = name;\n  }\n\n  [Symbol.for('Stream.toStreamable')]() {\n    return `hello ${this.#name}`;\n  }\n}\n\nconst stream = fromSync(new Greeting('world'));\nconsole.log(textSync(stream)); // 'hello world'"}],"children":[]}]}]}