@@ -18,6 +18,13 @@ functions or objects with a `transform` method.
1818Data flows in ** batches** ({Uint8Array\[ ] } per iteration) to amortize the cost
1919of async operations.
2020
21+ The module implements the WinterTC [ Iterable Streams API] [ ] draft. The
22+ classic stream interop functions ([ ` fromReadable() ` ] [ ] , [ ` fromWritable() ` ] [ ] ,
23+ [ ` toReadable() ` ] [ ] , [ ` toReadableSync() ` ] [ ] and [ ` toWritable() ` ] [ ] ),
24+ [ ` Broadcast.from() ` ] [ ] , [ ` Share.from() ` ] [ ] , [ ` SyncShare.fromSync() ` ] [ ] and the
25+ protocol symbols exported by ` Stream ` are Node.js extensions that are not part
26+ of the draft.
27+
2128``` mjs
2229import { from , pull , text } from ' node:stream/iter' ;
2330import { compressGzip , decompressGzip } from ' node:zlib/iter' ;
@@ -407,6 +414,18 @@ converted to a `USVString` and then UTF-8 encoded. `writev()` and
407414chunks. Writer option dictionaries treat ` null ` as an empty dictionary and
408415ignore unknown members.
409416
417+ Arguments are converted before the write itself starts. If the conversion runs
418+ user code (for example a ` toString() ` method, or the iterator of a ` writev() `
419+ argument) that writes to the same writer, those writes are ordered before the
420+ write whose argument is being converted, and they count against the same
421+ backpressure limits.
422+
423+ After ` end() ` or ` endSync() ` has been called, and until all buffered data has
424+ been consumed, the writer is _ closing_ . While closing, ` canWrite ` is ` null ` ,
425+ ` write() ` and ` writev() ` reject with a ` TypeError ` , ` writeSync() ` and
426+ ` writevSync() ` return ` false ` , ` endSync() ` returns ` -1 ` , and calling ` end() `
427+ again returns the same promise as the first call.
428+
410429Each async method has a synchronous ` *Sync ` counterpart designed for a
411430try-fallback pattern: attempt the fast synchronous path first, and fall back
412431to the async version only when the synchronous call indicates it could not
@@ -855,6 +874,10 @@ run().catch(console.error);
855874
856875The writer returned by ` push() ` conforms to the \[ Writer interface] \[ ] .
857876
877+ Zero-length chunks are accepted without being buffered: they are not delivered
878+ to the consumer, and ` writeSync() ` and ` write() ` report success for them even
879+ when backpressure is active.
880+
858881## Duplex channels
859882
860883### ` duplex([options]) `
@@ -1239,7 +1262,12 @@ added: v25.9.0
12391262
12401263Merge multiple async iterables by yielding batches in temporal order
12411264(whichever source produces data first). All sources are consumed
1242- concurrently.
1265+ concurrently, with at most one pending ` next() ` call per source.
1266+
1267+ If a source fails, the returned iterable rejects with its error. ` merge() `
1268+ calls ` return() ` on the other sources but does not wait for it to settle: an
1269+ async generator source that is suspended in an ` await ` only runs its cleanup
1270+ once that ` await ` completes.
12431271
12441272``` mjs
12451273import { from , merge , text } from ' node:stream/iter' ;
@@ -1265,8 +1293,9 @@ run().catch(console.error);
12651293added: v25.9.0
12661294-->
12671295
1268- * ` callback ` {Function} ` (chunks) => void ` Called with each batch and with
1269- ` null ` when the source ends.
1296+ * ` callback ` {Function} ` (chunks, options) => void ` Called with each batch and
1297+ with ` null ` when the source ends. ` options.signal ` is the pipeline's
1298+ {AbortSignal}.
12701299* Returns: {Function} A stateless transform.
12711300
12721301Create a pass-through transform that observes batches without modifying them.
@@ -1391,6 +1420,10 @@ run().catch(console.error);
13911420Cancel the broadcast. If ` reason ` is provided, all consumers reject with that
13921421exact reason. If it is omitted, consumers complete normally.
13931422
1423+ Cancelling also closes the paired writer: afterwards its ` canWrite ` is ` null `
1424+ and ` write() ` rejects with a ` TypeError ` . This lets a [ ` Broadcast.from() ` ] [ ]
1425+ pump stop pulling from its source.
1426+
13941427#### ` broadcast.consumerCount `
13951428
13961429* {number}
@@ -2282,13 +2315,19 @@ const stream = fromSync(new Greeting('world'));
22822315console .log (textSync (stream)); // 'hello world'
22832316` ` `
22842317
2318+ [Iterable Streams API]: https://iter-streams.proposal.wintertc.org/
22852319[` -- experimental- stream- iter` ]: cli.md#--experimental-stream-iter
2320+ [` Broadcast .from ()` ]: #broadcastfrominput-options
2321+ [` Share .from ()` ]: #static-method-sharefrominput-options
2322+ [` SyncShare .fromSync ()` ]: #static-method-syncsharefromsyncinput-options
22862323[` array ()` ]: #arraysource-options
22872324[` arrayBuffer ()` ]: #arraybuffersource-options
22882325[` bytes ()` ]: #bytessource-options
22892326[` dump ()` ]: #drainsource-options
22902327[` from ()` ]: #frominput
2328+ [` fromReadable ()` ]: #fromreadablereadable
22912329[` fromSync ()` ]: #fromsyncinput
2330+ [` fromWritable ()` ]: #fromwritablewritable-options
22922331[` node: zlib/ iter` ]: zlib.md#iterable-compression
22932332[` ondrain ()` ]: #ondraindrainable
22942333[` pipeTo ()` ]: #pipetosource-transforms-writer-options
@@ -2300,3 +2339,6 @@ console.log(textSync(stream)); // 'hello world'
23002339[` tap ()` ]: #tapcallback
23012340[` text ()` ]: #textsource-options
23022341[` toAsyncStreamable` ]: #streamtoasyncstreamable
2342+ [` toReadable ()` ]: #toreadablesource-options
2343+ [` toReadableSync ()` ]: #toreadablesyncsource-options
2344+ [` toWritable ()` ]: #towritablewriter
0 commit comments