Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node/zlib): cast Dataview and Buffer to uint8 #21746

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cli/tests/unit_node/zlib_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
4 changes: 4 additions & 0 deletions ext/node/polyfills/_brotli.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const toU8 = (input) => {
return enc.encode(input);
}

if (input.buffer) {
return new Uint8Array(input.buffer);
}

return input;
};

Expand Down