mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
fix(ext/node): createBrotliCompress params (#24984)
Fixes https://github.com/denoland/deno/issues/24416
This commit is contained in:
parent
82884348cb
commit
feba133711
2 changed files with 27 additions and 2 deletions
|
@ -3,9 +3,11 @@
|
||||||
import { core, primordials } from "ext:core/mod.js";
|
import { core, primordials } from "ext:core/mod.js";
|
||||||
const {
|
const {
|
||||||
Uint8Array,
|
Uint8Array,
|
||||||
|
Number,
|
||||||
PromisePrototypeThen,
|
PromisePrototypeThen,
|
||||||
PromisePrototypeCatch,
|
PromisePrototypeCatch,
|
||||||
ObjectValues,
|
ObjectEntries,
|
||||||
|
ArrayPrototypeMap,
|
||||||
TypedArrayPrototypeSlice,
|
TypedArrayPrototypeSlice,
|
||||||
TypedArrayPrototypeSubarray,
|
TypedArrayPrototypeSubarray,
|
||||||
TypedArrayPrototypeGetByteLength,
|
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);
|
this.#context = op_create_brotli_compress(params);
|
||||||
const context = this.#context;
|
const context = this.#context;
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,3 +191,22 @@ Deno.test("brotli decompress flush restore size", async () => {
|
||||||
);
|
);
|
||||||
assertEquals(output.length, input.length);
|
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);
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue