Compression
zlib.createGzip()
Creates a transform emitting gzip data. Connect it with pipeline for backpressure and error propagation. The example uses two small in-memory chunks. Tested on Node.js 22.16.0. Example output (one line per entry): ["bookstore"].
Formal Syntax & Structure
nodejs syntaxnodejs
zlib.createGzip([options])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| options | object | Compression and stream options. |
Return Value
Gzip
Compression transform.
Working Example
Example Snippetnodejs
import { createGzip, gunzipSync } from 'node:zlib';import { Readable, Writable } from 'node:stream';import { pipeline } from 'node:stream/promises';const parts = [];await pipeline(Readable.from(['book', 'store']), createGzip(), new Writable({ write(c, e, cb) { parts.push(c); cb(); } }));console.log(gunzipSync(Buffer.concat(parts)).toString());