From 80e9be3d5be8292f3b30dda3c98a4bbf9a986c1c Mon Sep 17 00:00:00 2001 From: Damian Krzeminski Date: Sun, 8 Oct 2023 23:00:59 +0200 Subject: [PATCH] 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 --- doc/api/webstreams.md | 4 ++-- lib/internal/webstreams/compression.js | 10 ++++++++-- test/parallel/test-whatwg-webstreams-compression.js | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/doc/api/webstreams.md b/doc/api/webstreams.md index 6d75212aba4a3f..aef563ab6a3d68 100644 --- a/doc/api/webstreams.md +++ b/doc/api/webstreams.md @@ -1422,7 +1422,7 @@ changes: added: v17.0.0 --> -* `format` {string} One of either `'deflate'` or `'gzip'`. +* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`. #### `compressionStream.readable` @@ -1456,7 +1456,7 @@ changes: added: v17.0.0 --> -* `format` {string} One of either `'deflate'` or `'gzip'`. +* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`. #### `decompressionStream.readable` diff --git a/lib/internal/webstreams/compression.js b/lib/internal/webstreams/compression.js index 6cbaa3f3250e73..d912959e29fd23 100644 --- a/lib/internal/webstreams/compression.js +++ b/lib/internal/webstreams/compression.js @@ -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; @@ -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; diff --git a/test/parallel/test-whatwg-webstreams-compression.js b/test/parallel/test-whatwg-webstreams-compression.js index c527fc1f13d10e..fb20801543bff6 100644 --- a/test/parallel/test-whatwg-webstreams-compression.js +++ b/test/parallel/test-whatwg-webstreams-compression.js @@ -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), {