stream: stream/iter node.js streams interop#62469
Open
jasnell wants to merge 4 commits intonodejs:mainfrom
Open
stream: stream/iter node.js streams interop#62469jasnell wants to merge 4 commits intonodejs:mainfrom
jasnell wants to merge 4 commits intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62469 +/- ##
==========================================
- Coverage 89.71% 89.70% -0.01%
==========================================
Files 695 696 +1
Lines 214434 215365 +931
Branches 41062 41233 +171
==========================================
+ Hits 192371 193197 +826
- Misses 14124 14224 +100
- Partials 7939 7944 +5
🚀 New features to boost your workflow:
|
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
guybedford
reviewed
Mar 30, 2026
mcollina
requested changes
Mar 31, 2026
Member
mcollina
left a comment
There was a problem hiding this comment.
I would prefer if these utilities to be exposed only in the new iter module as a function utilities instead of attaching them to the node stream
prototype
Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode/Opus 4.6
Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode/Opus 4.6
Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode/Opus 4.6
e16afd4 to
fb49804
Compare
Member
Author
|
@mcollina @guybedford please take another look |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implementing prototype integration points for experimental stream/iter and node.js stream.Readable/stream.Writable
Five utility functions are exported from
stream/iterto bridge between classic Node.js streams and the iterable streams API. These are available asrequire('node:stream/iter').fromReadable, etc.From classic to
stream/iterfromReadable(readable)— Converts a classicstream.Readable(or duck-typed object withread()andon()) into anAsyncIterable<Uint8Array[]>suitable for use withfrom(),pull(),text(), etc.toAsyncStreamableprotocol (asstream.Readabledoes via its prototype), that path is used.read()+EventEmitterand wraps with the same batched async iterator logic.Readablestreams are automatically normalized toUint8Array.WeakMap.fromWritable(writable[, options])— Converts a classicstream.Writable(or duck-typed object withwrite()andon()) into astream/iterWriteradapter suitable for use withpipeTo().'strict'(default — rejects on full buffer),'block'(waits for drain),'drop-newest'(silently discards).'drop-oldest'is rejected because theWritable's internal buffer has no batch boundaries — awritev()fans out into individual entries, so evicting oldest entries could partially tear apart an earlier atomic batch.writeSync/writevSyncalways returnfalseandendSyncreturns-1.writableHighWaterMark,writableLength, etc.Writerinterface is bytes-only).'drain'/'error'listener pair (not per-write listeners) with a waiters list that is swapped on resolution forO(n)cleanup.WeakMap.end(),fail(), and dispose.From
stream/iterto classictoReadable(source[, options])— Creates a byte-modestream.Readablefrom anAsyncIterable<Uint8Array[]>. Each batch's chunks are pushed individually. SupportshighWaterMarkand signal options. Uses an async pump withPromiseWithResolvers-based backpressure.toReadableSync(source[, options])— Same but for synchronousIterable<Uint8Array[]>. The_read()method pulls from the iterator directly.toWritable(writer)— Creates astream.Writablebacked by astream/iterWriter. Uses the try-sync-first pattern:_writeattemptswriteSyncbefore falling back toawait write(),_writevattemptswritevSyncbeforeawait writev(),_finalattemptsendSyncbeforeawait end(). Sync-success callbacks are deferred viaqueueMicrotaskto preserveWritable's async callback contract. TheWritable'shighWaterMarkis set toNumber.MAX_SAFE_INTEGERto disable its internal buffering — the underlyingWritermanages backpressure directly. Onlywrite()is required on theWriter;end(),fail(),writev(), and all sync variants are optional.Protocol:
Readable.prototype[Symbol.for('Stream.toAsyncStreamable')]Remains on the
Readableprototype so thatfrom(readable)discovers it automatically. Delegates tocreateBatchedAsyncIterator(shared withfromReadable's duck-type path) to avoid code duplication. The protocol method calls the shared helper directly — it does NOT callfromReadable(), which would create infinite recursion sincefromReadablechecks for the protocol.Signed-off-by: James M Snell jasnell@gmail.com
Assisted-by: Opencode/Opus 4.6