Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: add support for deflate-raw format to webstreams compression #50097

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions doc/api/webstreams.md
Original file line number Diff line number Diff line change
Expand Up @@ -1420,9 +1420,13 @@ changes:

<!-- YAML
added: v17.0.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/50097
description: format now accepts `deflate-raw` value.
-->

* `format` {string} One of either `'deflate'` or `'gzip'`.
* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`.
pirxpilot marked this conversation as resolved.
Show resolved Hide resolved

#### `compressionStream.readable`

Expand Down Expand Up @@ -1454,9 +1458,13 @@ changes:

<!-- YAML
added: v17.0.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/50097
description: format now accepts `deflate-raw` value.
-->

* `format` {string} One of either `'deflate'` or `'gzip'`.
pirxpilot marked this conversation as resolved.
Show resolved Hide resolved
* `format` {string} One of `'deflate'`, `'deflate-raw'`, or `'gzip'`.

#### `decompressionStream.readable`

Expand Down
10 changes: 8 additions & 2 deletions lib/internal/webstreams/compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-whatwg-webstreams-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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), {
Expand Down