diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-08-02 15:44:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-02 16:44:32 +0200 |
commit | b82a2f114c7c936bf4398669453513ace478cb1d (patch) | |
tree | a0dd2aa94cf61103b1dbcfa28a6c67feebf6eedd | |
parent | 7495bcbf77349d708b249944a149c16f5ee0c667 (diff) |
fix(ext/node): node:zlib coerces quality 10 to 9.5 (#24850)
Fixes https://github.com/denoland/deno/issues/24572
-rw-r--r-- | ext/node/polyfills/_brotli.js | 9 | ||||
-rw-r--r-- | tests/unit_node/zlib_test.ts | 14 |
2 files changed, 22 insertions, 1 deletions
diff --git a/ext/node/polyfills/_brotli.js b/ext/node/polyfills/_brotli.js index 1524bf85c..6b4020724 100644 --- a/ext/node/polyfills/_brotli.js +++ b/ext/node/polyfills/_brotli.js @@ -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, diff --git a/tests/unit_node/zlib_test.ts b/tests/unit_node/zlib_test.ts index 215717dde..eb248c34d 100644 --- a/tests/unit_node/zlib_test.ts +++ b/tests/unit_node/zlib_test.ts @@ -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", () => { |