-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
stream: accept ArrayBuffer in CompressionStream and DecompressionStream #61913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nodejs-github-bot
merged 7 commits into
nodejs:main
from
suuuuuuminnnnnn:fix/webstreams-arraybuffer-write
Mar 2, 2026
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
91009bf
stream: accept ArrayBuffer in CompressionStream and DecompressionStream
suuuuuuminnnnnn b0bbe51
stream: guard ArrayBuffer normalization and simplify test
suuuuuuminnnnnn 25e32d0
test: migrate webstreams compression buffer-source test to node:test
suuuuuuminnnnnn c664603
test: simplify webstreams compression regression test
suuuuuuminnnnnn aa1901c
test: remove unused reader variable in compression buffer-source test
suuuuuuminnnnnn d791f39
test: simplify round-trip test using Array.fromAsync
suuuuuuminnnnnn 6de7441
test: add adapter WritableStream ArrayBuffer and objectMode coverage
suuuuuuminnnnnn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
71 changes: 71 additions & 0 deletions
71
test/parallel/test-webstreams-compression-buffer-source.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| 'use strict'; | ||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const { DecompressionStream, CompressionStream } = require('stream/web'); | ||
|
|
||
| // Minimal gzip-compressed bytes for "hello" | ||
| const compressedGzip = new Uint8Array([ | ||
| 31, 139, 8, 0, 0, 0, 0, 0, 0, 3, | ||
| 203, 72, 205, 201, 201, 7, 0, 134, 166, 16, 54, 5, 0, 0, 0, | ||
| ]); | ||
|
|
||
| async function testDecompressionAcceptsArrayBuffer() { | ||
| const ds = new DecompressionStream('gzip'); | ||
| const reader = ds.readable.getReader(); | ||
| const writer = ds.writable.getWriter(); | ||
|
|
||
| const writePromise = writer.write(compressedGzip.buffer); | ||
| writer.close(); | ||
|
|
||
| const chunks = []; | ||
| let done = false; | ||
| while (!done) { | ||
| const { value, done: d } = await reader.read(); | ||
| if (value) chunks.push(value); | ||
| done = d; | ||
| } | ||
|
Renegade334 marked this conversation as resolved.
Outdated
|
||
| await writePromise; | ||
| const out = Buffer.concat(chunks.map((c) => Buffer.from(c))); | ||
| assert.strictEqual(out.toString(), 'hello'); | ||
| } | ||
|
|
||
| async function testCompressionRoundTripWithArrayBuffer() { | ||
| const cs = new CompressionStream('gzip'); | ||
| const ds = new DecompressionStream('gzip'); | ||
|
|
||
| const csWriter = cs.writable.getWriter(); | ||
| const csReader = cs.readable.getReader(); | ||
| const dsWriter = ds.writable.getWriter(); | ||
| const dsReader = ds.readable.getReader(); | ||
|
|
||
| const input = new TextEncoder().encode('hello').buffer; | ||
|
|
||
| await csWriter.write(input); | ||
| csWriter.close(); | ||
|
|
||
| const compressed = []; | ||
| let done = false; | ||
| while (!done) { | ||
| const { value, done: d } = await csReader.read(); | ||
| if (value) compressed.push(value); | ||
| done = d; | ||
| } | ||
|
|
||
| for (const chunk of compressed) await dsWriter.write(chunk); | ||
| dsWriter.close(); | ||
|
MattiasBuelens marked this conversation as resolved.
Outdated
|
||
|
|
||
| const out = []; | ||
| done = false; | ||
| while (!done) { | ||
| const { value, done: d } = await dsReader.read(); | ||
| if (value) out.push(value); | ||
| done = d; | ||
| } | ||
| const result = Buffer.concat(out.map((c) => Buffer.from(c))); | ||
| assert.strictEqual(result.toString(), 'hello'); | ||
| } | ||
|
|
||
| Promise.all([ | ||
| testDecompressionAcceptsArrayBuffer(), | ||
| testCompressionRoundTripWithArrayBuffer(), | ||
| ]).then(common.mustCall()); | ||
|
MattiasBuelens marked this conversation as resolved.
Outdated
|
||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.