diff --git a/cli/tests/unit_node/zlib_test.ts b/cli/tests/unit_node/zlib_test.ts index 957c7cdfcd984f..a6d1647915d382 100644 --- a/cli/tests/unit_node/zlib_test.ts +++ b/cli/tests/unit_node/zlib_test.ts @@ -3,6 +3,7 @@ import { assert, assertEquals } from "../../../test_util/std/assert/mod.ts"; import { fromFileUrl, relative } from "../../../test_util/std/path/mod.ts"; import { + brotliCompress, brotliCompressSync, brotliDecompressSync, createBrotliCompress, @@ -19,6 +20,18 @@ Deno.test("brotli compression sync", () => { assertEquals(decompressed.toString(), "hello world"); }); +Deno.test("brotli compression async", async () => { + const buf = Buffer.from("hello world"); + const compressed: Buffer = await new Promise((resolve) => + brotliCompress(buf, (_, res) => { + return resolve(res); + }) + ); + assertEquals(compressed instanceof Buffer, true); + const decompressed = brotliDecompressSync(compressed); + assertEquals(decompressed.toString(), "hello world"); +}); + Deno.test("brotli compression", async () => { const { promise, resolve } = Promise.withResolvers(); const compress = createBrotliCompress(); diff --git a/ext/node/polyfills/_brotli.js b/ext/node/polyfills/_brotli.js index cd54eedda82497..d39f2d5f6ccf74 100644 --- a/ext/node/polyfills/_brotli.js +++ b/ext/node/polyfills/_brotli.js @@ -126,7 +126,7 @@ export function brotliCompress( const { quality, lgwin, mode } = oneOffCompressOptions(options); op_brotli_compress_async(buf, quality, lgwin, mode) - .then((result) => callback(null, result)) + .then((result) => callback(null, Buffer.from(result))) .catch((err) => callback(err)); }