# Referencia de la API node:zlib

`node:zlib` admite API con funciones de retorno, síncronas y de flujos.

| Familia | Compatibilidad |
|---|---|
| Deflate | Funciones de compresión/descompresión con envoltorio y sin procesar, variantes `Sync`, clases y auxiliares `create*` |
| Gzip | Gzip, gunzip, unzip, variantes `Sync`, clases y auxiliares `create*` |
| Brotli | Funciones de compresión/descompresión, clases y auxiliares `create*` |
| Zstandard | Funciones de compresión/descompresión, clases y auxiliares `create*` |
| Utilidades | `crc32`, `constants` y `codes` |

```javascript
const zlib = require("node:zlib");
const input = Buffer.from("hello, zlib!");

const gzip = zlib.gzipSync(input);
zlib.gunzipSync(gzip).toString(); // "hello, zlib!"

const zstd = zlib.zstdCompressSync(input);
zlib.zstdDecompressSync(zstd).toString(); // "hello, zlib!"
```

Las formas con funciones de retorno reciben `(error, result)`; las formas síncronas devuelven un
`Buffer` o lanzan una excepción.

## node:zlib/iter

El módulo de iteradores específico de Elide proporciona fábricas de transformación para gzip,
deflate, deflate sin procesar, Brotli y Zstandard. Una fábrica devuelve un objeto con
`.transform(asyncIterable)`; la salida llega en lotes de fragmentos de bytes.

```javascript
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
  }
}
```

Use [Flujos de compresión](/docs/api-whatwg-compression) con Web Streams.

## Véase también

- [API de zlib de Node.js](https://nodejs.org/api/zlib.html)

<!-- 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 -->
