Skip to content

Commit

Permalink
fix(ext/node): expose brotli stream APIs (#27943)
Browse files Browse the repository at this point in the history
Fixes #27170
  • Loading branch information
littledivy authored Feb 4, 2025
1 parent 61faa32 commit f28bbcc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ext/node/polyfills/_zlib.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -654,4 +654,4 @@ util.inherits(DeflateRaw, Zlib);
util.inherits(InflateRaw, Zlib);
util.inherits(Unzip, Zlib);

export { Deflate, DeflateRaw, Gunzip, Gzip, Inflate, InflateRaw, Unzip };
export { Deflate, DeflateRaw, Gunzip, Gzip, Inflate, InflateRaw, Unzip, Zlib };
21 changes: 5 additions & 16 deletions ext/node/polyfills/zlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ import {
unzipSync,
} from "ext:deno_node/_zlib.mjs";
import {
BrotliCompress,
brotliCompress,
brotliCompressSync,
BrotliDecompress,
brotliDecompress,
brotliDecompressSync,
createBrotliCompress,
Expand Down Expand Up @@ -113,21 +115,7 @@ export class BrotliOptions {
notImplemented("BrotliOptions.prototype.constructor");
}
}
export class BrotliCompress {
constructor() {
notImplemented("BrotliCompress.prototype.constructor");
}
}
export class BrotliDecompress {
constructor() {
notImplemented("BrotliDecompress.prototype.constructor");
}
}
export class ZlibBase {
constructor() {
notImplemented("ZlibBase.prototype.constructor");
}
}

export { constants };

export default {
Expand Down Expand Up @@ -216,12 +204,13 @@ export default {
Z_SYNC_FLUSH: constants.Z_SYNC_FLUSH,
Z_VERSION_ERROR: constants.Z_VERSION_ERROR,
ZLIB_VERNUM: constants.ZLIB_VERNUM,
ZlibBase,
};

export {
BrotliCompress,
brotliCompress,
brotliCompressSync,
BrotliDecompress,
brotliDecompress,
brotliDecompressSync,
codes,
Expand Down
27 changes: 27 additions & 0 deletions tests/unit_node/zlib_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import { assert, assertEquals, assertThrows } from "@std/assert";
import { fromFileUrl, relative } from "@std/path";
import {
BrotliCompress,
brotliCompress,
brotliCompressSync,
BrotliDecompress,
brotliDecompress,
brotliDecompressSync,
constants,
Expand Down Expand Up @@ -237,3 +239,28 @@ Deno.test("crc32()", () => {
// @ts-expect-error: passing an object
assertThrows(() => crc32({}), TypeError);
});

Deno.test("BrotliCompress", async () => {
const deffered = Promise.withResolvers<void>();
// @ts-ignore: BrotliCompress is not typed
const brotliCompress = new BrotliCompress();
// @ts-ignore: BrotliDecompress is not typed
const brotliDecompress = new BrotliDecompress();

brotliCompress.pipe(brotliDecompress);

let data = "";
brotliDecompress.on("data", (v: Buffer) => {
data += v.toString();
});

brotliDecompress.on("end", () => {
deffered.resolve();
});

brotliCompress.write("hello");
brotliCompress.end();

await deffered.promise;
assertEquals(data, "hello");
});

0 comments on commit f28bbcc

Please sign in to comment.