mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -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:
parent
7495bcbf77
commit
b82a2f114c
2 changed files with 22 additions and 1 deletions
|
@ -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,
|
||||
|
|
|
@ -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",
|
||||
() => {
|
||||
|
|
Loading…
Reference in a new issue