Skip to content

Commit 86a5c7f

Browse files
committed
stream: add support for deflate-raw format to webstreams compression
this change makes `deflate-raw` a valid parameter for both CompressionStream and DecompressionStream constructors it makes node's implementation consistent with what modern browsers support and what specification calls for see: https://wicg.github.io/compression/#compression-stream
1 parent 387e292 commit 86a5c7f

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

doc/api/webstreams.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -1420,9 +1420,13 @@ changes:
14201420
14211421
<!-- YAML
14221422
added: v17.0.0
1423+
changes:
1424+
- version: REPLACEME
1425+
pr-url: https://github.com/nodejs/node/pull/50097
1426+
description: format now accepts `deflate-raw` value
14231427
-->
14241428
1425-
* `format` {string} One of either `'deflate'` or `'gzip'`.
1429+
* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`.
14261430
14271431
#### `compressionStream.readable`
14281432
@@ -1454,9 +1458,13 @@ changes:
14541458
14551459
<!-- YAML
14561460
added: v17.0.0
1461+
changes:
1462+
- version: REPLACEME
1463+
pr-url: https://github.com/nodejs/node/pull/50097
1464+
description: format now accepts `deflate-raw` value
14571465
-->
14581466
1459-
* `format` {string} One of either `'deflate'` or `'gzip'`.
1467+
* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`.
14601468
14611469
#### `decompressionStream.readable`
14621470

lib/internal/webstreams/compression.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@ class CompressionStream {
3535
#transform;
3636

3737
/**
38-
* @param {'deflate'|'gzip'} format
38+
* @param {'deflate'|'deflate-raw'|'gzip'} format
3939
*/
4040
constructor(format) {
4141
switch (format) {
4242
case 'deflate':
4343
this.#handle = lazyZlib().createDeflate();
4444
break;
45+
case 'deflate-raw':
46+
this.#handle = lazyZlib().createDeflateRaw();
47+
break;
4548
case 'gzip':
4649
this.#handle = lazyZlib().createGzip();
4750
break;
@@ -80,13 +83,16 @@ class DecompressionStream {
8083
#transform;
8184

8285
/**
83-
* @param {'deflate'|'gzip'} format
86+
* @param {'deflate'|'deflate-raw'|'gzip'} format
8487
*/
8588
constructor(format) {
8689
switch (format) {
8790
case 'deflate':
8891
this.#handle = lazyZlib().createInflate();
8992
break;
93+
case 'deflate-raw':
94+
this.#handle = lazyZlib().createInflateRaw();
95+
break;
9096
case 'gzip':
9197
this.#handle = lazyZlib().createGunzip();
9298
break;

test/parallel/test-whatwg-webstreams-compression.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async function test(format) {
3838
]);
3939
}
4040

41-
Promise.all(['gzip', 'deflate'].map((i) => test(i))).then(common.mustCall());
41+
Promise.all(['gzip', 'deflate', 'deflate-raw'].map((i) => test(i))).then(common.mustCall());
4242

4343
[1, 'hello', false, {}].forEach((i) => {
4444
assert.throws(() => new CompressionStream(i), {

0 commit comments

Comments
 (0)