Skip to main content

Module zlib

Module zlib 

Source
Expand description

Node zlib module — real DEFLATE / zlib / gzip / brotli / zstd + CRC-32.

One-shot compression is backed by real codecs: flate2 for deflate/zlib/gzip (Compression::default() == level 6, matching node’s default), the brotli crate (quality 11, lgwin 22 — node’s BROTLI_DEFAULT_QUALITY/BROTLI_DEFAULT_WINDOW) for brotli, and zstd (level 3 == ZSTD_CLEVEL_DEFAULT) for zstd. Round-trips and cross-decoding with the real node binary hold for every codec, and zlib.crc32 uses crc32fast.

Every one-shot function ships in both flavours: the synchronous *Sync form returns a Buffer directly, and the asynchronous form runs the same codec and invokes callback(err, buffer) via a queued microtask (node’s zlib async work is off-thread, but the codecs here are fast enough to run inline before the callback fires, so results are identical). zlib.unzip/unzipSync auto-detect gzip vs zlib framing by magic bytes, matching node’s Unzip.

The streaming transform classes (Deflate, Gunzip, BrotliCompress, …) and their create* factories still require a streaming Transform backend we don’t have here, so those return an honest “not supported” error rather than a silently-wrong result.

Constants§

MODULE_METHODS
zlib module functions routed through stdlib::call.

Functions§

call