Compression
zlib.gzipSync()
Produces gzip-format bytes synchronously. Limit work to small inputs in synchronous code; choose streaming or async work on request paths. Compression is not encryption. Tested on Node.js 22.16.0. Example output (one line per entry): ["true true"].
Formal Syntax & Structure
nodejs syntaxnodejs
zlib.gzipSync(buffer[, options])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| buffer | Buffer | string | TypedArray | DataView | ArrayBuffer | Input. |
| options | object | Compression options. |
Return Value
Buffer
Gzip bytes.
Working Example
Example Snippetnodejs
import { gzipSync, gunzipSync } from 'node:zlib';const input = Buffer.from('book '.repeat(100));const packed = gzipSync(input);console.log(packed[0] === 0x1f && packed[1] === 0x8b, gunzipSync(packed).equals(input));