diff --git a/doc/api/globals.md b/doc/api/globals.md index 7d272e127cecfa..9d146b2e97dd2e 100644 --- a/doc/api/globals.md +++ b/doc/api/globals.md @@ -330,6 +330,9 @@ with the [`--no-experimental-websocket`][] CLI flag. -* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`. +* `format` {string} One of `'deflate'`, `'deflate-raw'`, `'gzip'`, or `'brotli'`. #### `compressionStream.readable` @@ -1520,6 +1523,9 @@ changes: -* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`. +* `format` {string} One of `'deflate'`, `'deflate-raw'`, `'gzip'`, or `'brotli'`. #### `decompressionStream.readable` diff --git a/lib/internal/webstreams/compression.js b/lib/internal/webstreams/compression.js index b33b7134096c8b..836c02f7341f70 100644 --- a/lib/internal/webstreams/compression.js +++ b/lib/internal/webstreams/compression.js @@ -28,6 +28,7 @@ const formatConverter = createEnumConverter('CompressionFormat', [ 'deflate', 'deflate-raw', 'gzip', + 'brotli', ]); /** @@ -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, { @@ -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); } @@ -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, { @@ -111,6 +115,9 @@ class DecompressionStream { rejectGarbageAfterEnd: true, }); break; + case 'brotli': + this.#handle = lazyZlib().createBrotliDecompress(); + break; } this.#transform = newReadableWritablePairFromDuplex(this.#handle); diff --git a/test/parallel/test-whatwg-webstreams-compression.js b/test/parallel/test-whatwg-webstreams-compression.js index c144a0a2e3d43d..bf87696eed1b2f 100644 --- a/test/parallel/test-whatwg-webstreams-compression.js +++ b/test/parallel/test-whatwg-webstreams-compression.js @@ -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), {