Skip to content

Commit

Permalink
fix(node/zlib): consistently return buffer (#21747)
Browse files Browse the repository at this point in the history
This fixes point 3 of #20516

This PR creates consistency between the sync and async versions of the
brotli compress where we will always return a buffer like Node.
  • Loading branch information
JoviDeCroock authored and bartlomieju committed Jan 4, 2024
1 parent 2319c51 commit ce539e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions cli/tests/unit_node/zlib_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<void>();
const compress = createBrotliCompress();
Expand Down
2 changes: 1 addition & 1 deletion ext/node/polyfills/_brotli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit ce539e9

Please sign in to comment.