mirror of
https://github.com/denoland/deno.git
synced 2025-02-12 16:59:32 -05:00
fix(ext/node): fix async variant of brotliDecompress (#27815)
Fixes https://github.com/denoland/deno/issues/27729
This commit is contained in:
parent
802b9d6309
commit
a2d0872225
2 changed files with 12 additions and 3 deletions
|
@ -181,7 +181,6 @@ export function brotliCompress(
|
||||||
callback = options;
|
callback = options;
|
||||||
options = {};
|
options = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const { quality, lgwin, mode } = oneOffCompressOptions(options);
|
const { quality, lgwin, mode } = oneOffCompressOptions(options);
|
||||||
PromisePrototypeCatch(
|
PromisePrototypeCatch(
|
||||||
PromisePrototypeThen(
|
PromisePrototypeThen(
|
||||||
|
@ -204,8 +203,13 @@ export function brotliCompressSync(
|
||||||
return Buffer.from(TypedArrayPrototypeSubarray(output, 0, len));
|
return Buffer.from(TypedArrayPrototypeSubarray(output, 0, len));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function brotliDecompress(input) {
|
export function brotliDecompress(input, options, callback) {
|
||||||
const buf = toU8(input);
|
const buf = toU8(input);
|
||||||
|
|
||||||
|
if (typeof options === "function") {
|
||||||
|
callback = options;
|
||||||
|
options = {};
|
||||||
|
}
|
||||||
return PromisePrototypeCatch(
|
return PromisePrototypeCatch(
|
||||||
PromisePrototypeThen(
|
PromisePrototypeThen(
|
||||||
op_brotli_decompress_async(buf),
|
op_brotli_decompress_async(buf),
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { fromFileUrl, relative } from "@std/path";
|
||||||
import {
|
import {
|
||||||
brotliCompress,
|
brotliCompress,
|
||||||
brotliCompressSync,
|
brotliCompressSync,
|
||||||
|
brotliDecompress,
|
||||||
brotliDecompressSync,
|
brotliDecompressSync,
|
||||||
constants,
|
constants,
|
||||||
crc32,
|
crc32,
|
||||||
|
@ -35,7 +36,11 @@ Deno.test("brotli compression async", async () => {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
assertEquals(compressed instanceof Buffer, true);
|
assertEquals(compressed instanceof Buffer, true);
|
||||||
const decompressed = brotliDecompressSync(compressed);
|
const decompressed: Buffer = await new Promise((resolve) =>
|
||||||
|
brotliDecompress(compressed, (_, res) => {
|
||||||
|
return resolve(res);
|
||||||
|
})
|
||||||
|
);
|
||||||
assertEquals(decompressed.toString(), "hello world");
|
assertEquals(decompressed.toString(), "hello world");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue