node:zlib matches Node, including Brotli, Zstandard, and crc32. For Web Streams, use
Compression Streams.
node:zlib/iter
node:zlib/iter is an Elide extension. It exports compress* and decompress* factories (Gzip, Deflate,
DeflateRaw, Brotli, Zstd, each with a Sync form) and the aliases gzip, gunzip, deflate, inflate,
deflateRaw, and inflateRaw. Each factory’s .transform(asyncIterable) yields batches of byte chunks.
import { gzip } from "node:zlib/iter";
async function* input() {
yield new TextEncoder().encode("hello");
}
for await (const batch of gzip().transform(input())) {
for (const chunk of batch) {
// compressed bytes
}
}