Skip to content

Commit

Permalink
fix(ext/node): fix async variant of brotliDecompress (#27815)
Browse files Browse the repository at this point in the history
Fixes #27729
  • Loading branch information
littledivy authored Jan 27, 2025
1 parent 802b9d6 commit a2d0872
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions ext/node/polyfills/_brotli.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ export function brotliCompress(
callback = options;
options = {};
}

const { quality, lgwin, mode } = oneOffCompressOptions(options);
PromisePrototypeCatch(
PromisePrototypeThen(
Expand All @@ -204,8 +203,13 @@ 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 = {};
}
return PromisePrototypeCatch(
PromisePrototypeThen(
op_brotli_decompress_async(buf),
Expand Down
7 changes: 6 additions & 1 deletion tests/unit_node/zlib_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { fromFileUrl, relative } from "@std/path";
import {
brotliCompress,
brotliCompressSync,
brotliDecompress,
brotliDecompressSync,
constants,
crc32,
Expand Down Expand Up @@ -35,7 +36,11 @@ Deno.test("brotli compression async", async () => {
})
);
assertEquals(compressed instanceof Buffer, true);
const decompressed = brotliDecompressSync(compressed);
const decompressed: Buffer = await new Promise((resolve) =>
brotliDecompress(compressed, (_, res) => {
return resolve(res);
})
);
assertEquals(decompressed.toString(), "hello world");
});

Expand Down

0 comments on commit a2d0872

Please sign in to comment.