Skip to content

Commit 8dc6f5b

Browse files
KhafraDevtargos
authored andcommitted
stream: add brotli support to CompressionStream and DecompressionStream
Refs: whatwg/compression#34 PR-URL: #59464 Reviewed-By: Mattias Buelens <mattias@buelens.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
1 parent ed33958 commit 8dc6f5b

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

doc/api/globals.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ with the [`--no-experimental-websocket`][] CLI flag.
330330
<!-- YAML
331331
added: v18.0.0
332332
changes:
333+
- version: REPLACEME
334+
pr-url: https://github.com/nodejs/node/pull/59464
335+
description: format now accepts `brotli` value.
333336
- version:
334337
- v23.11.0
335338
- v22.15.0
@@ -445,6 +448,9 @@ A browser-compatible implementation of {CustomEvent}.
445448
<!-- YAML
446449
added: v18.0.0
447450
changes:
451+
- version: REPLACEME
452+
pr-url: https://github.com/nodejs/node/pull/59464
453+
description: format now accepts `brotli` value.
448454
- version:
449455
- v23.11.0
450456
- v22.15.0

doc/api/webstreams.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,14 +1480,17 @@ changes:
14801480
<!-- YAML
14811481
added: v17.0.0
14821482
changes:
1483+
- version: REPLACEME
1484+
pr-url: https://github.com/nodejs/node/pull/59464
1485+
description: format now accepts `brotli` value.
14831486
- version:
14841487
- v21.2.0
14851488
- v20.12.0
14861489
pr-url: https://github.com/nodejs/node/pull/50097
14871490
description: format now accepts `deflate-raw` value.
14881491
-->
14891492
1490-
* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`.
1493+
* `format` {string} One of `'deflate'`, `'deflate-raw'`, `'gzip'`, or `'brotli'`.
14911494
14921495
#### `compressionStream.readable`
14931496
@@ -1520,14 +1523,17 @@ changes:
15201523
<!-- YAML
15211524
added: v17.0.0
15221525
changes:
1526+
- version: REPLACEME
1527+
pr-url: https://github.com/nodejs/node/pull/59464
1528+
description: format now accepts `brotli` value.
15231529
- version:
15241530
- v21.2.0
15251531
- v20.12.0
15261532
pr-url: https://github.com/nodejs/node/pull/50097
15271533
description: format now accepts `deflate-raw` value.
15281534
-->
15291535
1530-
* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`.
1536+
* `format` {string} One of `'deflate'`, `'deflate-raw'`, `'gzip'`, or `'brotli'`.
15311537
15321538
#### `decompressionStream.readable`
15331539

lib/internal/webstreams/compression.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const formatConverter = createEnumConverter('CompressionFormat', [
2828
'deflate',
2929
'deflate-raw',
3030
'gzip',
31+
'brotli',
3132
]);
3233

3334
/**
@@ -40,7 +41,7 @@ class CompressionStream {
4041
#transform;
4142

4243
/**
43-
* @param {'deflate'|'deflate-raw'|'gzip'} format
44+
* @param {'deflate'|'deflate-raw'|'gzip'|'brotli'} format
4445
*/
4546
constructor(format) {
4647
format = formatConverter(format, {
@@ -57,6 +58,9 @@ class CompressionStream {
5758
case 'gzip':
5859
this.#handle = lazyZlib().createGzip();
5960
break;
61+
case 'brotli':
62+
this.#handle = lazyZlib().createBrotliCompress();
63+
break;
6064
}
6165
this.#transform = newReadableWritablePairFromDuplex(this.#handle);
6266
}
@@ -90,7 +94,7 @@ class DecompressionStream {
9094
#transform;
9195

9296
/**
93-
* @param {'deflate'|'deflate-raw'|'gzip'} format
97+
* @param {'deflate'|'deflate-raw'|'gzip'|'brotli'} format
9498
*/
9599
constructor(format) {
96100
format = formatConverter(format, {
@@ -111,6 +115,9 @@ class DecompressionStream {
111115
rejectGarbageAfterEnd: true,
112116
});
113117
break;
118+
case 'brotli':
119+
this.#handle = lazyZlib().createBrotliDecompress();
120+
break;
114121
}
115122
this.#transform = newReadableWritablePairFromDuplex(this.#handle);
116123

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

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

44-
Promise.all(['gzip', 'deflate', 'deflate-raw'].map((i) => test(i))).then(common.mustCall());
44+
Promise.all(['gzip', 'deflate', 'deflate-raw', 'brotli'].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)