Skip to content

Commit ade6614

Browse files
pirxpilotrichardlau
authored andcommitted
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 PR-URL: #50097 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
1 parent 4ee7f29 commit ade6614

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
@@ -1416,9 +1416,13 @@ changes:
14161416
14171417
<!-- YAML
14181418
added: v17.0.0
1419+
changes:
1420+
- version: REPLACEME
1421+
pr-url: https://github.com/nodejs/node/pull/50097
1422+
description: format now accepts `deflate-raw` value.
14191423
-->
14201424
1421-
* `format` {string} One of either `'deflate'` or `'gzip'`.
1425+
* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`.
14221426
14231427
#### `compressionStream.readable`
14241428
@@ -1450,9 +1454,13 @@ changes:
14501454
14511455
<!-- YAML
14521456
added: v17.0.0
1457+
changes:
1458+
- version: REPLACEME
1459+
pr-url: https://github.com/nodejs/node/pull/50097
1460+
description: format now accepts `deflate-raw` value.
14531461
-->
14541462
1455-
* `format` {string} One of either `'deflate'` or `'gzip'`.
1463+
* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`.
14561464
14571465
#### `decompressionStream.readable`
14581466

lib/internal/webstreams/compression.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ function isDecompressionStream(value) {
5151

5252
class CompressionStream {
5353
/**
54-
* @param {'deflate'|'gzip'} format
54+
* @param {'deflate'|'deflate-raw'|'gzip'} format
5555
*/
5656
constructor(format) {
5757
this[kType] = 'CompressionStream';
5858
switch (format) {
5959
case 'deflate':
6060
this[kHandle] = lazyZlib().createDeflate();
6161
break;
62+
case 'deflate-raw':
63+
this[kHandle] = lazyZlib().createDeflateRaw();
64+
break;
6265
case 'gzip':
6366
this[kHandle] = lazyZlib().createGzip();
6467
break;
@@ -100,14 +103,17 @@ class CompressionStream {
100103

101104
class DecompressionStream {
102105
/**
103-
* @param {'deflate'|'gzip'} format
106+
* @param {'deflate'|'deflate-raw'|'gzip'} format
104107
*/
105108
constructor(format) {
106109
this[kType] = 'DecompressionStream';
107110
switch (format) {
108111
case 'deflate':
109112
this[kHandle] = lazyZlib().createInflate();
110113
break;
114+
case 'deflate-raw':
115+
this[kHandle] = lazyZlib().createInflateRaw();
116+
break;
111117
case 'gzip':
112118
this[kHandle] = lazyZlib().createGunzip();
113119
break;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async function test(format) {
4141
]);
4242
}
4343

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

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

0 commit comments

Comments
 (0)