diff options
-rw-r--r-- | ext/node/polyfills/_brotli.js | 10 | ||||
-rw-r--r-- | tests/unit_node/zlib_test.ts | 19 |
2 files changed, 27 insertions, 2 deletions
diff --git a/ext/node/polyfills/_brotli.js b/ext/node/polyfills/_brotli.js index 6b4020724..0dcb58e04 100644 --- a/ext/node/polyfills/_brotli.js +++ b/ext/node/polyfills/_brotli.js @@ -3,9 +3,11 @@ import { core, primordials } from "ext:core/mod.js"; const { Uint8Array, + Number, PromisePrototypeThen, PromisePrototypeCatch, - ObjectValues, + ObjectEntries, + ArrayPrototypeMap, TypedArrayPrototypeSlice, TypedArrayPrototypeSubarray, TypedArrayPrototypeGetByteLength, @@ -114,7 +116,11 @@ export class BrotliCompress extends Transform { }, }); - const params = ObjectValues(options?.params ?? {}); + const params = ArrayPrototypeMap( + ObjectEntries(options?.params ?? {}), + // Undo the stringification of the keys + (o) => [Number(o[0]), o[1]], + ); this.#context = op_create_brotli_compress(params); const context = this.#context; } diff --git a/tests/unit_node/zlib_test.ts b/tests/unit_node/zlib_test.ts index eb248c34d..8bce5ce7d 100644 --- a/tests/unit_node/zlib_test.ts +++ b/tests/unit_node/zlib_test.ts @@ -191,3 +191,22 @@ Deno.test("brotli decompress flush restore size", async () => { ); assertEquals(output.length, input.length); }); + +Deno.test("createBrotliCompress params", async () => { + const compress = createBrotliCompress({ + params: { + [constants.BROTLI_PARAM_QUALITY]: 11, + }, + }); + + const input = new Uint8Array(10000); + for (let i = 0; i < input.length; i++) { + input[i] = Math.random() * 256; + } + const output = await buffer( + Readable.from([input]) + .pipe(compress) + .pipe(createBrotliDecompress()), + ); + assertEquals(output.length, input.length); +}); |