From ade6614067964f9ec31309f5bcc0043afce27ec3 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 c53f0b880249a1..ec55e35ce16774 100644 --- a/doc/api/webstreams.md +++ b/doc/api/webstreams.md @@ -1416,9 +1416,13 @@ changes: -* `format` {string} One of either `'deflate'` or `'gzip'`. +* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`. #### `compressionStream.readable` @@ -1450,9 +1454,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 cda3c4b08f3b5b..28b6dc8f7a41bf 100644 --- a/lib/internal/webstreams/compression.js +++ b/lib/internal/webstreams/compression.js @@ -51,7 +51,7 @@ function isDecompressionStream(value) { class CompressionStream { /** - * @param {'deflate'|'gzip'} format + * @param {'deflate'|'deflate-raw'|'gzip'} format */ constructor(format) { this[kType] = 'CompressionStream'; @@ -59,6 +59,9 @@ class CompressionStream { case 'deflate': this[kHandle] = lazyZlib().createDeflate(); break; + case 'deflate-raw': + this[kHandle] = lazyZlib().createDeflateRaw(); + break; case 'gzip': this[kHandle] = lazyZlib().createGzip(); break; @@ -100,7 +103,7 @@ class CompressionStream { class DecompressionStream { /** - * @param {'deflate'|'gzip'} format + * @param {'deflate'|'deflate-raw'|'gzip'} format */ constructor(format) { this[kType] = 'DecompressionStream'; @@ -108,6 +111,9 @@ class DecompressionStream { case 'deflate': this[kHandle] = lazyZlib().createInflate(); break; + case 'deflate-raw': + this[kHandle] = lazyZlib().createInflateRaw(); + break; case 'gzip': this[kHandle] = lazyZlib().createGunzip(); break; diff --git a/test/parallel/test-whatwg-webstreams-compression.js b/test/parallel/test-whatwg-webstreams-compression.js index f9ae8d87265b58..1d0882c4d1a681 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'].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), {