Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
  • Loading branch information
pirxpilot committed Oct 9, 2023
commit 0331b7af5073c3bcf6ca9a2834e74cf211a3cb91
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'`.
Comment thread
pirxpilot marked this conversation as resolved.

#### `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'`.
Comment thread
pirxpilot marked this conversation as resolved.
* `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