1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(ext/node): createBrotliCompress params (#24984)

Fixes https://github.com/denoland/deno/issues/24416
This commit is contained in:
Divy Srivastava 2024-08-11 01:56:30 -07:00 committed by GitHub
parent 82884348cb
commit feba133711
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 2 deletions

View file

@ -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;
}

View file

@ -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);
});