From f7756103d0b22eedcde0b5c7ffe298b4f384f8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Cla=C3=9Fen?= Date: Fri, 13 Dec 2024 18:57:49 +0100 Subject: [PATCH] Improve brotliDecompress. Fixes: Uncaught (in promise) ReferenceError: callback is not defined Test program that should then pass: import zlib from 'node:zlib'; import { promisify } from 'node:util'; import { Buffer } from 'node:buffer'; const brotliDecompress = promisify(zlib.brotliDecompress); (async () => { const result = await brotliDecompress(Buffer.from([0x21, 0x0c, 0x00, 0x04, 0x74, 0x65, 0x73, 0x74, 0x03])); console.log(result.toString()); // should print "test" })(); --- ext/node/polyfills/_brotli.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ext/node/polyfills/_brotli.js b/ext/node/polyfills/_brotli.js index ebd03515615ec0..e7d594fe5662be 100644 --- a/ext/node/polyfills/_brotli.js +++ b/ext/node/polyfills/_brotli.js @@ -193,8 +193,19 @@ export function brotliCompressSync( return Buffer.from(TypedArrayPrototypeSubarray(output, 0, len)); } -export function brotliDecompress(input) { +export function brotliDecompress( + input, + options, + callback, +) { const buf = toU8(input); + + if (typeof options === "function") { + callback = options; + options = {}; + } + + // note: `options` argument is currently not used return PromisePrototypeCatch( PromisePrototypeThen( op_brotli_decompress_async(buf),