# node:zlib

> How Elide supports Node's `zlib` module: Deflate, Gzip, Brotli, Zstandard and crc32 match Node, plus the `node:zlib/iter` async-iterator extension.

`node:zlib` follows [Node's `zlib`](https://nodejs.org/api/zlib.html), including Brotli, Zstandard, and `crc32`. For
Web Streams, use [Compression Streams](https://elide.help/docs/api-whatwg-compression).

## Example

```js
// zlib.mjs
import { brotliCompressSync, crc32, gunzipSync, gzipSync, zstdCompressSync, zstdDecompressSync } from "node:zlib";

const text = "elide ".repeat(100);
const gz = gzipSync(text);
console.log(text.length, "->", gz.length, gunzipSync(gz).toString() === text);
console.log(zstdDecompressSync(zstdCompressSync(text)).toString().length);
console.log(brotliCompressSync(text).length < text.length, crc32("elide"));
```

`elide run zlib.mjs` prints:

```text
600 -> 35 true
600
true 2639236160
```

## Differences from Node

- Constants live only on `zlib.constants`; the top-level `Z_*`, `ZSTD_*` and mode aliases such as `zlib.Z_OK`
  are `undefined`.
- `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, as in
  `for await (const batch of gzip().transform(input))`.

<!-- api-reference:start 1bb2678b653c -->
## Reference

**Status:** Partial · Not measured · since 1.1.0

### Exports

| Export | Kind | Status | Notes |
| --- | --- | --- | --- |
| `deflateSync()` | function | Full | Compress data using the deflate algorithm (RFC 1951 wrapped in zlib format RFC 1950) |
| `inflateSync()` | function | Full | Decompress data that was compressed with deflate (zlib format) |
| `deflateRawSync()` | function | Full | Compress data using the deflate algorithm in raw mode (no zlib header, RFC 1951) |
| `inflateRawSync()` | function | Full | Decompress raw deflate data (no zlib header) |
| `gzipSync()` | function | Full | Compress data using gzip (RFC 1952) |
| `gunzipSync()` | function | Full | Decompress gzip data (RFC 1952) |
| `brotliCompressSync()` | function | Full | Compress data using the Brotli algorithm (RFC 7932) |
| `brotliDecompressSync()` | function | Full | Decompress Brotli-compressed data (RFC 7932) |
| `unzipSync()` | function | Full | Decompress data with automatic format detection (gzip or deflate) |
| `constants` | property | Full | The `constants` object exposes zlib, Brotli, and Zstd numeric constants |
| top-level constants | constant | Partial | `Z_NO_COMPRESSION`, `Z_BEST_SPEED`, `Z_BEST_COMPRESSION`, `Z_DEFAULT_COMPRESSION`, `Z_FILTERED`, `Z_HUFFMAN_ONLY` and 73 more |

### Not implemented

107 top-level constants such as `DEFLATE`.
<!-- api-reference:end -->
