Skip to content

Commit

Permalink
Improve brotliDecompress.
Browse files Browse the repository at this point in the history
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"
    })();
  • Loading branch information
philipp-classen committed Dec 13, 2024
1 parent 32b57f7 commit f775610
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ext/node/polyfills/_brotli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit f775610

Please sign in to comment.