Zlib bindings
The zlib
module provides single-call-oriented functions for interacting with zlib data.
- Source
Methods
deflate(str_or_resource, gzipopt, nullable, levelopt, nullable) → {string}nullable
Compresses data in Zlib or gzip format.
If the input argument is a plain string, it is directly compressed.
If an array, object or resource value is given, this function will attempt to invoke a read()
method on it to read chunks of input text to incrementally compress. Reading will stop if the object's read()
method returns either null
or an empty string.
Throws an exception on errors.
Returns the compressed data.
Name | Type | Description |
---|---|---|
str_or_resource | string | The string or resource object to be parsed as JSON. |
gzip | boolean | (optional, nullable, default: false )Add a gzip header if true (creates a gzip-compliant output, otherwise defaults to Zlib) |
level | number | (optional, nullable, default: Z_DEFAULT_COMPRESSION )The compression level (0-9). |
// deflate content using default compression
const deflated = deflate(content);
// deflate content using fastest compression
const deflated = deflate(content, Z_BEST_SPEED);
- Source
inflate(str_or_resource) → {string}nullable
Decompresses data in Zlib or gzip format.
If the input argument is a plain string, it is directly decompressed.
If an array, object or resource value is given, this function will attempt to invoke a read()
method on it to read chunks of input text to incrementally decompress. Reading will stop if the object's read()
method returns either null
or an empty string.
Throws an exception on errors.
Returns the decompressed data.
Name | Type | Description |
---|---|---|
str_or_resource | string | The string or resource object to be parsed as JSON. |
- Source
Type Definitions
Compression levels
Constants representing predefined compression levels.
Name | Type | Description |
---|---|---|
Z_NO_COMPRESSION. | number | |
Z_BEST_SPEED. | number | |
Z_BEST_COMPRESSION. | number | |
Z_DEFAULT_COMPRESSION | number | default compromise between speed and compression (currently equivalent to level 6). |
- Source