webstreams: accept ArrayBuffer in WritableStream write sink#61913
Open
suuuuuuminnnnnn wants to merge 6 commits intonodejs:mainfrom
Open
webstreams: accept ArrayBuffer in WritableStream write sink#61913suuuuuuminnnnnn wants to merge 6 commits intonodejs:mainfrom
suuuuuuminnnnnn wants to merge 6 commits intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
30ebba1 to
91009bf
Compare
MattiasBuelens
requested changes
Feb 21, 2026
Renegade334
reviewed
Feb 21, 2026
Comment on lines
20
to
26
| const chunks = []; | ||
| let done = false; | ||
| while (!done) { | ||
| const { value, done: d } = await reader.read(); | ||
| if (value) chunks.push(value); | ||
| done = d; | ||
| } |
Member
There was a problem hiding this comment.
Nit: Similar to Mattias's comment, this iteration doesn't need to be done manually:
Suggested change
| const chunks = []; | |
| let done = false; | |
| while (!done) { | |
| const { value, done: d } = await reader.read(); | |
| if (value) chunks.push(value); | |
| done = d; | |
| } | |
| const chunks = await Array.fromAsync(ds.readable); |
Author
There was a problem hiding this comment.
Good catch, thanks both — I'll apply this suggestion too.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61913 +/- ##
==========================================
- Coverage 89.75% 89.75% -0.01%
==========================================
Files 674 674
Lines 204416 204893 +477
Branches 39285 39377 +92
==========================================
+ Hits 183472 183892 +420
- Misses 13227 13283 +56
- Partials 7717 7718 +1
🚀 New features to boost your workflow:
|
Author
|
Thanks @MattiasBuelens and @Renegade334 — applied both suggestions.
I kept the PR scoped to the |
Contributor
Failed to start CI⚠ No approving reviews found ✘ Refusing to run CI on potentially unsafe PRhttps://github.com/nodejs/node/actions/runs/22255119973 |
MattiasBuelens
approved these changes
Feb 21, 2026
Collaborator
jazelly
approved these changes
Feb 21, 2026
jazelly
approved these changes
Feb 21, 2026
Comment on lines
40
to
46
| const out = []; | ||
| let done = false; | ||
| while (!done) { | ||
| const { value, done: d } = await dsReader.read(); | ||
| if (value) out.push(value); | ||
| done = d; | ||
| } |
Contributor
There was a problem hiding this comment.
Nit-pick: you could also use Array.fromAsync here. 😉
Author
There was a problem hiding this comment.
Done, applied to both tests. Thanks!
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.
Per the WHATWG Compression Streams spec,
CompressionStreamandDecompressionStreammust acceptBufferSource(
ArrayBuffer | ArrayBufferView) as valid chunk types.Currently, writing a plain
ArrayBufferto the writable side throwsERR_INVALID_ARG_TYPE, because the adapter innewWritableStreamFromStreamWritablepasses chunks directly tostream.write(), which only acceptsArrayBufferViewtypes.This change normalizes plain
ArrayBufferchunks to aUint8Arrayviewbefore forwarding them to the underlying Node.js stream.
Changes included:
ArrayBuffertoUint8Arrayinlib/internal/webstreams/adapters.jsArrayBufferinputBufferSourcetest (if passing)Fixes: #43433