mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
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.
This commit is contained in:
parent
08fc8d50e3
commit
4339a6c55d
2 changed files with 14 additions and 1 deletions
|
@ -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<void>();
|
||||
const compress = createBrotliCompress();
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue