Compression

zlib.gunzip()

Decodes gzip bytes asynchronously. Use an output cap for bounded convenience decoding and also limit input and concurrency. Tested on Node.js 22.16.0. Example output (one line per entry): ["book"].

Formal Syntax & Structure

nodejs syntaxnodejs
zlib.gunzip(buffer[, options], callback)

Parameters & Attributes

NameTypeDescription
bufferBuffer | string | TypedArray | DataView | ArrayBufferCompressed data.
optionsobjectDecompression options.
callbackFunctionError-first completion callback.

Return Value

undefined

Decoded Buffer delivered by callback.

Working Example

Example Snippetnodejs
import { gzipSync, gunzip } from 'node:zlib';import { promisify } from 'node:util';const decoded = await promisify(gunzip)(gzipSync('book'), { maxOutputLength: 64 });console.log(decoded.toString());
Node.js Reference