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
6 changes: 6 additions & 0 deletions doc/api/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ with the [`--no-experimental-websocket`][] CLI flag.
<!-- YAML
added: v18.0.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/59464
description: format now accepts `brotli` value.
- version:
- v23.11.0
- v22.15.0
Expand Down Expand Up @@ -445,6 +448,9 @@ A browser-compatible implementation of {CustomEvent}.
<!-- YAML
added: v18.0.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/59464
description: format now accepts `brotli` value.
- version:
- v23.11.0
- v22.15.0
Expand Down
10 changes: 8 additions & 2 deletions doc/api/webstreams.md
Original file line number Diff line number Diff line change
Expand Up @@ -1480,14 +1480,17 @@ changes:
<!-- YAML
added: v17.0.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/59464
description: format now accepts `brotli` value.
- version:
- v21.2.0
- v20.12.0
pr-url: https://github.com/nodejs/node/pull/50097
description: format now accepts `deflate-raw` value.
-->
* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`.
* `format` {string} One of `'deflate'`, `'deflate-raw'`, `'gzip'`, or `'brotli'`.
#### `compressionStream.readable`
Expand Down Expand Up @@ -1520,14 +1523,17 @@ changes:
<!-- YAML
added: v17.0.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/59464
description: format now accepts `brotli` value.
- version:
- v21.2.0
- v20.12.0
pr-url: https://github.com/nodejs/node/pull/50097
description: format now accepts `deflate-raw` value.
-->
* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`.
* `format` {string} One of `'deflate'`, `'deflate-raw'`, `'gzip'`, or `'brotli'`.
#### `decompressionStream.readable`
Expand Down
11 changes: 9 additions & 2 deletions lib/internal/webstreams/compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const formatConverter = createEnumConverter('CompressionFormat', [
'deflate',
'deflate-raw',
'gzip',
'brotli',
]);

/**
Expand All @@ -40,7 +41,7 @@ class CompressionStream {
#transform;

/**
* @param {'deflate'|'deflate-raw'|'gzip'} format
* @param {'deflate'|'deflate-raw'|'gzip'|'brotli'} format
*/
constructor(format) {
format = formatConverter(format, {
Expand All @@ -57,6 +58,9 @@ class CompressionStream {
case 'gzip':
this.#handle = lazyZlib().createGzip();
break;
case 'brotli':
this.#handle = lazyZlib().createBrotliCompress();
break;
}
this.#transform = newReadableWritablePairFromDuplex(this.#handle);
}
Expand Down Expand Up @@ -90,7 +94,7 @@ class DecompressionStream {
#transform;

/**
* @param {'deflate'|'deflate-raw'|'gzip'} format
* @param {'deflate'|'deflate-raw'|'gzip'|'brotli'} format
*/
constructor(format) {
format = formatConverter(format, {
Expand All @@ -111,6 +115,9 @@ class DecompressionStream {
rejectGarbageAfterEnd: true,
});
break;
case 'brotli':
this.#handle = lazyZlib().createBrotliDecompress();
break;
}
this.#transform = newReadableWritablePairFromDuplex(this.#handle);

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 @@ -41,7 +41,7 @@ async function test(format) {
]);
}

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

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