1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix(ext/node): node:zlib coerces quality 10 to 9.5 (#24850)

Fixes https://github.com/denoland/deno/issues/24572
This commit is contained in:
Bartek Iwańczuk 2024-08-02 15:44:32 +01:00 committed by GitHub
parent 7495bcbf77
commit b82a2f114c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View file

@ -121,13 +121,20 @@ export class BrotliCompress extends Transform {
}
function oneOffCompressOptions(options) {
const quality = options?.params?.[constants.BROTLI_PARAM_QUALITY] ??
let quality = options?.params?.[constants.BROTLI_PARAM_QUALITY] ??
constants.BROTLI_DEFAULT_QUALITY;
const lgwin = options?.params?.[constants.BROTLI_PARAM_LGWIN] ??
constants.BROTLI_DEFAULT_WINDOW;
const mode = options?.params?.[constants.BROTLI_PARAM_MODE] ??
constants.BROTLI_MODE_GENERIC;
// NOTE(bartlomieju): currently the rust-brotli crate panics if the quality
// is set to 10. Coerce it down to 9.5 which is the maximum supported value.
// https://github.com/dropbox/rust-brotli/issues/216
if (quality == 10) {
quality = 9.5;
}
return {
quality,
lgwin,

View file

@ -6,6 +6,7 @@ import {
brotliCompress,
brotliCompressSync,
brotliDecompressSync,
constants,
createBrotliCompress,
createBrotliDecompress,
createDeflate,
@ -137,6 +138,19 @@ Deno.test("should work with a buffer from an encoded string", () => {
assertEquals(decompressed.toString(), "hello world");
});
// https://github.com/denoland/deno/issues/24572
Deno.test("Brotli quality 10 doesn't panic", () => {
const e = brotliCompressSync("abc", {
params: {
[constants.BROTLI_PARAM_QUALITY]: 10,
},
});
assertEquals(
new Uint8Array(e.buffer),
new Uint8Array([11, 1, 128, 97, 98, 99, 3]),
);
});
Deno.test(
"zlib compression with dataview",
() => {