Skip to content
Open
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
19 changes: 11 additions & 8 deletions doc/api/zlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,9 @@ Each Brotli-based class takes an `options` object. All options are optional.
* `finishFlush` {integer} **Default:** `zlib.constants.BROTLI_OPERATION_FINISH`
* `chunkSize` {integer} **Default:** `16 * 1024`
* `params` {Object} Key-value object containing indexed [Brotli parameters][].
* `dictionary` {Buffer|TypedArray|DataView|ArrayBuffer} Optional dictionary used
to improve compression efficiency when compressing or decompressing data that
shares common patterns with the dictionary.
* `maxOutputLength` {integer} Limits output size when using
[convenience methods][]. **Default:** [`buffer.kMaxLength`][]
* `info` {boolean} If `true`, returns an object with `buffer` and `engine`. **Default:** `false`
Expand Down Expand Up @@ -1857,7 +1860,7 @@ added: v25.9.0
* `BROTLI_PARAM_LGBLOCK` -- input block size (log2).
See the [Brotli compressor options][] in the zlib documentation for the
full list.
* `dictionary` {Buffer|TypedArray|DataView}
* `dictionary` {Buffer|TypedArray|DataView|ArrayBuffer}
* Returns: {Object} A stateful transform.

Create a Brotli compression transform. Output is compatible with
Expand All @@ -1877,7 +1880,7 @@ added: v25.9.0
* `windowBits` {number} **Default:** `Z_DEFAULT_WINDOWBITS` (15).
* `memLevel` {number} **Default:** `9`.
* `strategy` {number} **Default:** `Z_DEFAULT_STRATEGY`.
* `dictionary` {Buffer|TypedArray|DataView}
* `dictionary` {Buffer|TypedArray|DataView|ArrayBuffer}
* Returns: {Object} A stateful transform.

Create a deflate compression transform. Output is compatible with
Expand All @@ -1897,7 +1900,7 @@ added: v25.9.0
* `windowBits` {number} **Default:** `Z_DEFAULT_WINDOWBITS` (15).
* `memLevel` {number} **Default:** `9`.
* `strategy` {number} **Default:** `Z_DEFAULT_STRATEGY`.
* `dictionary` {Buffer|TypedArray|DataView}
* `dictionary` {Buffer|TypedArray|DataView|ArrayBuffer}
* Returns: {Object} A stateful transform.

Create a gzip compression transform. Output is compatible with `zlib.gunzip()`
Expand All @@ -1924,7 +1927,7 @@ added: v25.9.0
See the [Zstd compressor options][] in the zlib documentation for the
full list.
* `pledgedSrcSize` {number} Expected uncompressed size (optional hint).
* `dictionary` {Buffer|TypedArray|DataView}
* `dictionary` {Buffer|TypedArray|DataView|ArrayBuffer}
* Returns: {Object} A stateful transform.

Create a Zstandard compression transform. Output is compatible with
Expand All @@ -1948,7 +1951,7 @@ added: v25.9.0
Window Brotli" mode (not compatible with [RFC 7932][]).
See the [Brotli decompressor options][] in the zlib documentation for
details.
* `dictionary` {Buffer|TypedArray|DataView}
* `dictionary` {Buffer|TypedArray|DataView|ArrayBuffer}
* Returns: {Object} A stateful transform.

Create a Brotli decompression transform.
Expand All @@ -1964,7 +1967,7 @@ added: v25.9.0
* `options` {Object}
* `chunkSize` {number} Output buffer size. **Default:** `65536` (64 KB).
* `windowBits` {number} **Default:** `Z_DEFAULT_WINDOWBITS` (15).
* `dictionary` {Buffer|TypedArray|DataView}
* `dictionary` {Buffer|TypedArray|DataView|ArrayBuffer}
* Returns: {Object} A stateful transform.

Create a deflate decompression transform.
Expand All @@ -1980,7 +1983,7 @@ added: v25.9.0
* `options` {Object}
* `chunkSize` {number} Output buffer size. **Default:** `65536` (64 KB).
* `windowBits` {number} **Default:** `Z_DEFAULT_WINDOWBITS` (15).
* `dictionary` {Buffer|TypedArray|DataView}
* `dictionary` {Buffer|TypedArray|DataView|ArrayBuffer}
* Returns: {Object} A stateful transform.

Create a gzip decompression transform.
Expand All @@ -2001,7 +2004,7 @@ added: v25.9.0
will allocate. Limits memory usage against malicious input.
See the [Zstd decompressor options][] in the zlib documentation for
details.
* `dictionary` {Buffer|TypedArray|DataView}
* `dictionary` {Buffer|TypedArray|DataView|ArrayBuffer}
* Returns: {Object} A stateful transform.

Create a Zstandard decompression transform.
Expand Down
32 changes: 32 additions & 0 deletions test/parallel/test-stream-iter-transform-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,37 @@ function testEmptyInput() {
assert.strictEqual(result, '');
}

// =============================================================================
// Dictionary tests
// =============================================================================

function testDictionaryAcceptsArrayBufferAndView() {
const dict =
Buffer.from('the quick brown fox jumps over the lazy dog '.repeat(4));
const inputBuf = Buffer.from(dict);
const arrayBufferDict = dict.buffer.slice(
dict.byteOffset, dict.byteOffset + dict.byteLength);
const dataViewDict = new DataView(arrayBufferDict);

for (const [compress, decompress] of [
[compressBrotliSync, decompressBrotliSync],
[compressZstdSync, decompressZstdSync],
]) {
const withBuffer = bytesSync(
pullSync(fromSync(inputBuf), compress({ dictionary: dict }))).byteLength;

for (const dictionary of [arrayBufferDict, dataViewDict]) {
const size = bytesSync(
pullSync(fromSync(inputBuf), compress({ dictionary }))).byteLength;
assert.strictEqual(size, withBuffer);

const result = roundTripBytes(inputBuf, compress({ dictionary }),
decompress({ dictionary }));
assert.deepStrictEqual(result, inputBuf);
}
}
}

// =============================================================================
// Run all tests
// =============================================================================
Expand All @@ -223,5 +254,6 @@ testBrotliWithOptions();
testMixedStatelessAndStateful();
testEarlyExit();
testEmptyInput();
testDictionaryAcceptsArrayBufferAndView();

common.mustCall()();
Loading