From 08fc8d50e35a27835d497a631a6dcc0f733546de Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Sun, 31 Dec 2023 12:50:37 +0100 Subject: fix(node/zlib): cast Dataview and Buffer to uint8 (#21746) This fixes point 2 of #20516 This adds a conversion from Dataview/Buffer by returning `obj.buffer` which can be converted to a `UInt8Array`. Question: Regarding point 4 of the mentioned issue would it be appropriate to copy the toU8 helper to the `zlib.mjs` methods? --- cli/tests/unit_node/zlib_test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'cli/tests') diff --git a/cli/tests/unit_node/zlib_test.ts b/cli/tests/unit_node/zlib_test.ts index fc9eaeb5b..957c7cdfc 100644 --- a/cli/tests/unit_node/zlib_test.ts +++ b/cli/tests/unit_node/zlib_test.ts @@ -96,3 +96,19 @@ Deno.test( handle.destroy(); }, ); + +Deno.test("should work with dataview", () => { + const buf = Buffer.from("hello world"); + const compressed = brotliCompressSync(new DataView(buf.buffer)); + const decompressed = brotliDecompressSync(compressed); + assertEquals(decompressed.toString(), "hello world"); +}); + +Deno.test("should work with a buffer from an encoded string", () => { + const encoder = new TextEncoder(); + const buffer = encoder.encode("hello world"); + const buf = Buffer.from(buffer); + const compressed = brotliCompressSync(buf); + const decompressed = brotliDecompressSync(compressed); + assertEquals(decompressed.toString(), "hello world"); +}); -- cgit v1.2.3