Compression
zlib.deflateSync()
Produces a zlib-wrapped DEFLATE representation, which is not the gzip format. Match the encoder and decoder; the wrapper matters to interoperability. Tested on Node.js 22.16.0. Example output (one line per entry): ["true"].
Formal Syntax & Structure
nodejs syntaxnodejs
zlib.deflateSync(buffer[, options])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| buffer | Buffer | string | TypedArray | DataView | ArrayBuffer | Input. |
| options | object | Compression options. |
Return Value
Buffer
Zlib-wrapped compressed bytes.
Working Example
Example Snippetnodejs
import { deflateSync, inflateSync } from 'node:zlib';const payload = Buffer.from('catalog');console.log(inflateSync(deflateSync(payload)).equals(payload));