mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 20:38:55 +00:00
fix(node:zlib): gzip & gzipSync should accept ArrayBuffer (#26762)
Closes https://github.com/denoland/deno/issues/26638
This commit is contained in:
parent
700f54a13c
commit
b3a3d84ce2
@ -14,6 +14,7 @@ import { nextTick } from "ext:deno_node/_next_tick.ts";
|
||||
import {
|
||||
isAnyArrayBuffer,
|
||||
isArrayBufferView,
|
||||
isUint8Array,
|
||||
} from "ext:deno_node/internal/util/types.ts";
|
||||
|
||||
var kRangeErrorMessage = "Cannot create final Buffer. It would be larger " +
|
||||
@ -158,6 +159,12 @@ export const inflateRawSync = function (buffer, opts) {
|
||||
function sanitizeInput(input) {
|
||||
if (typeof input === "string") input = Buffer.from(input);
|
||||
|
||||
if (isArrayBufferView(input) && !isUint8Array(input)) {
|
||||
input = Buffer.from(input.buffer, input.byteOffset, input.byteLength);
|
||||
} else if (isAnyArrayBuffer(input)) {
|
||||
input = Buffer.from(input);
|
||||
}
|
||||
|
||||
if (
|
||||
!Buffer.isBuffer(input) &&
|
||||
(input.buffer && !input.buffer.constructor === ArrayBuffer)
|
||||
|
@ -10,6 +10,7 @@ import {
|
||||
createBrotliCompress,
|
||||
createBrotliDecompress,
|
||||
createDeflate,
|
||||
gzip,
|
||||
gzipSync,
|
||||
unzipSync,
|
||||
} from "node:zlib";
|
||||
@ -210,3 +211,17 @@ Deno.test("createBrotliCompress params", async () => {
|
||||
);
|
||||
assertEquals(output.length, input.length);
|
||||
});
|
||||
|
||||
Deno.test("gzip() and gzipSync() accept ArrayBuffer", async () => {
|
||||
const deffered = Promise.withResolvers<void>();
|
||||
const buf = new ArrayBuffer(0);
|
||||
let output: Buffer;
|
||||
gzip(buf, (_err, data) => {
|
||||
output = data;
|
||||
deffered.resolve();
|
||||
});
|
||||
await deffered.promise;
|
||||
assert(output! instanceof Buffer);
|
||||
const outputSync = gzipSync(buf);
|
||||
assert(outputSync instanceof Buffer);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user