From 4339a6c55db8252b54ee96e38e2e1b084e28d7e2 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Sun, 31 Dec 2023 12:53:09 +0100 Subject: fix(node/zlib): consistently return buffer (#21747) This fixes point 3 of https://github.com/denoland/deno/issues/20516 This PR creates consistency between the sync and async versions of the brotli compress where we will always return a buffer like Node. --- cli/tests/unit_node/zlib_test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'cli/tests/unit_node') diff --git a/cli/tests/unit_node/zlib_test.ts b/cli/tests/unit_node/zlib_test.ts index 957c7cdfc..a6d164791 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(); -- cgit v1.2.3