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 <[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]>
  • Loading branch information
pirxpilot authored Nov 9, 2023
1 parent bb2dd0e commit 3e14cfb
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
Original file line number Diff line number Diff line change
Expand Up @@ -1420,9 +1420,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 @@ -1454,9 +1458,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
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ class CompressionStream {
#transform;

/**
* @param {'deflate'|'gzip'} format
* @param {'deflate'|'deflate-raw'|'gzip'} format
*/
constructor(format) {
switch (format) {
case 'deflate':
this.#handle = lazyZlib().createDeflate();
break;
case 'deflate-raw':
this.#handle = lazyZlib().createDeflateRaw();
break;
case 'gzip':
this.#handle = lazyZlib().createGzip();
break;
Expand Down Expand Up @@ -80,13 +83,16 @@ class DecompressionStream {
#transform;

/**
* @param {'deflate'|'gzip'} format
* @param {'deflate'|'deflate-raw'|'gzip'} format
*/
constructor(format) {
switch (format) {
case 'deflate':
this.#handle = lazyZlib().createInflate();
break;
case 'deflate-raw':
this.#handle = lazyZlib().createInflateRaw();
break;
case 'gzip':
this.#handle = lazyZlib().createGunzip();
break;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-whatwg-webstreams-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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 3e14cfb

Please sign in to comment.