Skip to content

Commit

Permalink
stream: add support for deflate-raw format to webstreams compression
Browse files Browse the repository at this point in the history
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 <yagiz@nizipli.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
  • Loading branch information
pirxpilot authored and richardlau committed Mar 25, 2024
1 parent 4ee7f29 commit ade6614
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
12 changes: 10 additions & 2 deletions doc/api/webstreams.md
Expand Up @@ -1416,9 +1416,13 @@ changes:
<!-- YAML
added: v17.0.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/50097
description: format now accepts `deflate-raw` value.
-->
* `format` {string} One of either `'deflate'` or `'gzip'`.
* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`.
#### `compressionStream.readable`
Expand Down Expand Up @@ -1450,9 +1454,13 @@ changes:
<!-- YAML
added: v17.0.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/50097
description: format now accepts `deflate-raw` value.
-->
* `format` {string} One of either `'deflate'` or `'gzip'`.
* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`.
#### `decompressionStream.readable`
Expand Down
10 changes: 8 additions & 2 deletions lib/internal/webstreams/compression.js
Expand Up @@ -51,14 +51,17 @@ function isDecompressionStream(value) {

class CompressionStream {
/**
* @param {'deflate'|'gzip'} format
* @param {'deflate'|'deflate-raw'|'gzip'} format
*/
constructor(format) {
this[kType] = 'CompressionStream';
switch (format) {
case 'deflate':
this[kHandle] = lazyZlib().createDeflate();
break;
case 'deflate-raw':
this[kHandle] = lazyZlib().createDeflateRaw();
break;
case 'gzip':
this[kHandle] = lazyZlib().createGzip();
break;
Expand Down Expand Up @@ -100,14 +103,17 @@ class CompressionStream {

class DecompressionStream {
/**
* @param {'deflate'|'gzip'} format
* @param {'deflate'|'deflate-raw'|'gzip'} format
*/
constructor(format) {
this[kType] = 'DecompressionStream';
switch (format) {
case 'deflate':
this[kHandle] = lazyZlib().createInflate();
break;
case 'deflate-raw':
this[kHandle] = lazyZlib().createInflateRaw();
break;
case 'gzip':
this[kHandle] = lazyZlib().createGunzip();
break;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-whatwg-webstreams-compression.js
Expand Up @@ -41,7 +41,7 @@ async function test(format) {
]);
}

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

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

0 comments on commit ade6614

Please sign in to comment.