From 3e14cfbbcfcedbb18235ffd5cc28983ac5d5ca52 Mon Sep 17 00:00:00 2001 From: Damian Krzeminski Date: Thu, 9 Nov 2023 12:18:57 +0100 Subject: [PATCH] stream: add support for `deflate-raw` format to webstreams compression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 PR-URL: https://github.com/nodejs/node/pull/50097 Reviewed-By: Yagiz Nizipli Reviewed-By: Tobias Nießen Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Filip Skokan --- 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 03f95b87ff0b3c..3d0ba237fe7fea 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), {