From 86a5c7f645eb64e6b9d75a951f05b9169c4c176a 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 | 12 ++++++++++-- lib/internal/webstreams/compression.js | 10 ++++++++-- test/parallel/test-whatwg-webstreams-compression.js | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/doc/api/webstreams.md b/doc/api/webstreams.md index 6d75212aba4a3f..8f7634b9e17bf5 100644 --- a/doc/api/webstreams.md +++ b/doc/api/webstreams.md @@ -1420,9 +1420,13 @@ changes: -* `format` {string} One of either `'deflate'` or `'gzip'`. +* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`. #### `compressionStream.readable` @@ -1454,9 +1458,13 @@ changes: -* `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), {