Index of every page on this site: llms.txt
All skills
jasnell avatar

/node-stream-iter

@5f83e6c
Run it yourself

Experimental iterable-first streams API, node:stream/iter (behind --experimental-stream-iter). Use only when the user asks for stream/iter or that flag, or explicitly accepts an experimental API for async-iterable stream pipelines with backpressure. Without that opt-in, prefer classic node:stream for production code. Covers from/pull/pipeTo/push/duplex/broadcast/share, text/bytes/array consumers, transforms, filehandle.pull/writer, fromReadable/toReadable interop and node:zlib/iter compressGzip/decompressZstd. Node.js 24.20+ or 25.9+; behavior differs before 26.12.

Use this Skill: https://skilld.dev/gh/jasnell/node-skills/node-stream-iter

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

rulespush-duplex.md

≈863 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Push streams, writers, backpressure, duplex

push([...transforms][, options]) → { writer, readable }

Option Default Meaning
budget 16384 The number of buffered bytes before backpressure applies. Any positive integer on v26.12+; >= 16384 on v24.x (smaller throws ERR_OUT_OF_RANGE)
backpressure 'strict' 'strict', 'unbounded', 'drop-oldest' or 'drop-newest'
signal none Aborts the stream. It stays active while buffered data drains after end()

The transforms apply to the readable side. A zero-length write is accepted and never delivered.

Policies (two buffers: the buffer itself, capped at budget, and a queue of pending writes)

Policy Pending writes When full
'strict' 1 A further unawaited write() rejects with ERR_INVALID_STATE ("Backpressure violation: too many pending writes")
'unbounded' unlimited Writes queue forever, which can leak memory if you forget to await. This matches classic streams and web streams
'drop-oldest' never waits The oldest buffered data is evicted (for live feeds and telemetry)
'drop-newest' never waits The incoming write is discarded (for load shedding)

Rules:

  • Start the consumer (text(readable), for await) before you await writes, or run it concurrently. Otherwise the first write that fills the buffer waits forever.
  • Await every write(). Under 'strict' that guarantees at most one pending write.

Writer interface

Only write(chunk[, { signal }]) is required. The optional members are writev(chunks[, { signal }]), end([{ signal }]) (a Promise of the total bytes), fail(reason) (always synchronous), writeSync, writevSync (return booleans), endSync() (returns the bytes, or -1), canWrite (true, false, or null when closed), and [Symbol.asyncDispose] (fails an open writer, or waits for one that is closing).

  • A non-Uint8Array chunk is converted with String() and UTF-8 encoded. writev takes any iterable.
  • After end(), the writer is closing: write() rejects with a TypeError, writeSync() returns false, and a second end() returns the same promise.
  • An option signal cancels only that one operation. It does not fail the writer.

The try-sync-then-async pattern:

if (!writer.writeSync(chunk)) await writer.write(chunk);
if (writer.endSync() < 0) await writer.end();

ondrain(writer) → Promise<boolean> | null

This waits until buffered bytes fall below the budget. It returns null if the object does not implement Symbol.for('Stream.drainableProtocol'). It is useful with the drop policies, where it lets a producer wait instead of losing data. Prefer it over polling canWrite.

duplex([options]) → [a, b]

These are connected channels, like socketpair(): what one side's writer writes, the other side's readable yields. The options are budget, backpressure and signal (shared), plus a: {...} and b: {...} for per-direction overrides. Each end has writer, readable, close() (idempotent) and [Symbol.asyncDispose].

const [client, server] = duplex();
(async () => {
  for await (const chunks of server.readable) await server.writer.writev(chunks); // echo
  await server.writer.end();
})();
await client.writer.write('ping');
await client.writer.end();
await text(client.readable); // 'ping'

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts5d3 checks · Risk SAFE
  • Gen Agent Trust Hub5d

    The skill provides technical documentation and examples for the experimental Node.js stream/iter API. It does not perform network operations, access sensitive files, or execute remote code. It follows security best practices by recommending byte limits for untrusted input processing.

  • Socket5d

    No alerts

  • Snyk5d

    Risk: LOW · No issues

Signed by skilld at 5f83e6c. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 5 days ago.

Activeupdated last week

README badge

README badge for jasnell/node-skills/node-stream-iter