bare-zlib
Stream-based zlib bindings for JavaScript
bare-zlib — Stream-based zlib bindings for JavaScript. It is a native addon.
Mirrors the Node.js zlib module.
npm i bare-zlibAPI
Zlib
Zlib.constants
Zlib.constants: {
Z_NO_FLUSH: number
Z_PARTIAL_FLUSH: number
Z_SYNC_FLUSH: number
Z_FULL_FLUSH: number
Z_FINISH: number
Z_BLOCK: number
Z_TREES: number
Z_FILTERED: number
Z_HUFFMAN_ONLY: number
Z_RLE: number
Z_FIXED: number
Z_DEFAULT_STRATEGY: number
Z_NO_COMPRESSION: number
Z_BEST_SPEED: number
Z_BEST_COMPRESSION: number
Z_DEFAULT_COMPRESSION: number
Z_MIN_CHUNK: number
Z_MAX_CHUNK: number
Z_DEFAULT_CHUNK: number
Z_MIN_MEMLEVEL: number
Z_MAX_MEMLEVEL: number
Z_DEFAULT_MEMLEVEL: number
Z_MIN_LEVEL: number
Z_MAX_LEVEL: number
Z_DEFAULT_LEVEL: number
Z_MIN_WINDOWBITS: number
Z_MAX_WINDOWBITS: number
Z_DEFAULT_WINDOWBITS: number
Z_OK: number
Z_STREAM_END: number
Z_NEED_DICT: number
Z_ERRNO: number
Z_STREAM_ERROR: number
Z_DATA_ERROR: number
Z_MEM_ERROR: number
Z_BUF_ERROR: number
Z_VERSION_ERROR: number
}Zlib-related constants such as flush modes, compression levels, strategies, and chunk/window/memory-level bounds.
Zlib.createDeflate(opts?: ZlibOptions): Deflate
Source
Create and return a new Deflate stream for streaming zlib compression.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | ZlibOptions | — | Options for the stream and the underlying zlib state. |
Zlib.createDeflateRaw(opts?: ZlibOptions): DeflateRaw
Source
Create and return a new DeflateRaw stream for streaming raw deflate compression, without a zlib header.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | ZlibOptions | — | Options for the stream and the underlying zlib state. |
Zlib.createGunzip(opts?: ZlibOptions): Gunzip
Source
Create and return a new Gunzip stream for streaming gzip decompression.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | ZlibOptions | — | Options for the stream and the underlying zlib state. |
Zlib.createGzip(opts?: ZlibOptions): Gzip
Source
Create and return a new Gzip stream for streaming gzip compression.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | ZlibOptions | — | Options for the stream and the underlying zlib state. |
Zlib.createInflate(opts?: ZlibOptions): Inflate
Source
Create and return a new Inflate stream for streaming zlib decompression.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | ZlibOptions | — | Options for the stream and the underlying zlib state. |
Zlib.createInflateRaw(opts?: ZlibOptions): InflateRaw
Source
Create and return a new InflateRaw stream for streaming raw deflate decompression, without a zlib header.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | ZlibOptions | — | Options for the stream and the underlying zlib state. |
Zlib.deflate(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Source
Compress buffer with deflate, calling cb with the resulting Buffer.
Overloads:
Zlib.deflate(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Zlib.deflate(buffer: ZlibInput, cb: ZlibCallback): voidParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
buffer | ZlibInput | — | The data to compress. |
opts | ZlibOptions | — | The zlib options to apply for this operation. |
cb | ZlibCallback | — | Called with the resulting Buffer, or with an error if the operation fails. |
Zlib.deflateRaw(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Source
Compress buffer with raw deflate, without a zlib header, calling cb with the resulting Buffer.
Overloads:
Zlib.deflateRaw(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Zlib.deflateRaw(buffer: ZlibInput, cb: ZlibCallback): voidParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
buffer | ZlibInput | — | The data to compress. |
opts | ZlibOptions | — | The zlib options to apply for this operation. |
cb | ZlibCallback | — | Called with the resulting Buffer, or with an error if the operation fails. |
Zlib.deflateRawSync(buffer: ZlibInput, opts?: ZlibOptions): Buffer
Source
Synchronously compress buffer with raw deflate, without a zlib header, and return the resulting Buffer.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
buffer | ZlibInput | — | The data to compress; a string is converted to a Buffer. |
opts? | ZlibOptions | — | The zlib options to apply for this operation. |
Throws
LIMIT_EXCEEDED— the output exceededmaxOutputLength.ZlibError— the underlying zlib operation failed;codeidentifies the failure.
Zlib.deflateSync(buffer: ZlibInput, opts?: ZlibOptions): Buffer
Source
Synchronously compress buffer with deflate and return the resulting Buffer.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
buffer | ZlibInput | — | The data to compress; a string is converted to a Buffer. |
opts? | ZlibOptions | — | The zlib options to apply for this operation. |
Throws
LIMIT_EXCEEDED— the output exceededmaxOutputLength.ZlibError— the underlying zlib operation failed;codeidentifies the failure.
Zlib.gunzip(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Source
Decompress buffer as gzip, calling cb with the resulting Buffer.
Overloads:
Zlib.gunzip(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Zlib.gunzip(buffer: ZlibInput, cb: ZlibCallback): voidParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
buffer | ZlibInput | — | The data to decompress. |
opts | ZlibOptions | — | The zlib options to apply for this operation. |
cb | ZlibCallback | — | Called with the resulting Buffer, or with an error if the operation fails. |
Zlib.gunzipSync(buffer: ZlibInput, opts?: ZlibOptions): Buffer
Source
Synchronously decompress buffer as gzip and return the resulting Buffer.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
buffer | ZlibInput | — | The data to decompress; a string is converted to a Buffer. |
opts? | ZlibOptions | — | The zlib options to apply for this operation. |
Throws
LIMIT_EXCEEDED— the output exceededmaxOutputLength.ZlibError— the underlying zlib operation failed;code(such asDATA_ERROR) identifies the failure.
Zlib.gzip(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Source
Compress buffer as gzip, calling cb with the resulting Buffer.
Overloads:
Zlib.gzip(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Zlib.gzip(buffer: ZlibInput, cb: ZlibCallback): voidParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
buffer | ZlibInput | — | The data to compress. |
opts | ZlibOptions | — | The zlib options to apply for this operation. |
cb | ZlibCallback | — | Called with the resulting Buffer, or with an error if the operation fails. |
Zlib.gzipSync(buffer: ZlibInput, opts?: ZlibOptions): Buffer
Source
Synchronously compress buffer as gzip and return the resulting Buffer.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
buffer | ZlibInput | — | The data to compress; a string is converted to a Buffer. |
opts? | ZlibOptions | — | The zlib options to apply for this operation. |
Throws
LIMIT_EXCEEDED— the output exceededmaxOutputLength.ZlibError— the underlying zlib operation failed;codeidentifies the failure.
Zlib.inflate(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Source
Decompress buffer with inflate, calling cb with the resulting Buffer.
Overloads:
Zlib.inflate(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Zlib.inflate(buffer: ZlibInput, cb: ZlibCallback): voidParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
buffer | ZlibInput | — | The data to decompress. |
opts | ZlibOptions | — | The zlib options to apply for this operation. |
cb | ZlibCallback | — | Called with the resulting Buffer, or with an error if the operation fails. |
Zlib.inflateRaw(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Source
Decompress buffer with raw inflate, without a zlib header, calling cb with the resulting Buffer.
Overloads:
Zlib.inflateRaw(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Zlib.inflateRaw(buffer: ZlibInput, cb: ZlibCallback): voidParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
buffer | ZlibInput | — | The data to decompress. |
opts | ZlibOptions | — | The zlib options to apply for this operation. |
cb | ZlibCallback | — | Called with the resulting Buffer, or with an error if the operation fails. |
Zlib.inflateRawSync(buffer: ZlibInput, opts?: ZlibOptions): Buffer
Source
Synchronously decompress buffer with raw inflate, without a zlib header, and return the resulting Buffer.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
buffer | ZlibInput | — | The data to decompress; a string is converted to a Buffer. |
opts? | ZlibOptions | — | The zlib options to apply for this operation. |
Throws
LIMIT_EXCEEDED— the output exceededmaxOutputLength.ZlibError— the underlying zlib operation failed;code(such asDATA_ERROR) identifies the failure.
Zlib.inflateSync(buffer: ZlibInput, opts?: ZlibOptions): Buffer
Source
Synchronously decompress buffer with inflate and return the resulting Buffer.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
buffer | ZlibInput | — | The data to decompress; a string is converted to a Buffer. |
opts? | ZlibOptions | — | The zlib options to apply for this operation. |
Throws
LIMIT_EXCEEDED— the output exceededmaxOutputLength.ZlibError— the underlying zlib operation failed;code(such asDATA_ERROR) identifies the failure.
Zlib.ZlibInput
type ZlibInput = string | Buffer | Uint8ArrayThe input accepted by the one-shot functions: a string, Buffer, or Uint8Array.
ZlibStream
flush(mode?: number, cb?: ZlibFlushCallback): Promise<void>
Source
Flush queued data through the stream immediately using the given flush mode, resolving once it has drained.
Overloads:
flush(mode?: number, cb?: ZlibFlushCallback): Promise<void>
flush(cb: ZlibFlushCallback): Promise<void>Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
mode? | number | — | The flush mode, from constants (default Z_FULL_FLUSH). |
cb? | ZlibFlushCallback | — | Called once the flush completes, for Node.js compatibility; the returned promise resolves as well. |
reset(): void
Source
Reset the underlying compressor or decompressor to its initial state.
Throws
STREAM_CLOSED— the stream has already closed.
Deflate
new Deflate(opts?: ZlibOptions)
Source
Create a Deflate stream with the given opts.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | ZlibOptions | — | Options for the stream and the underlying zlib state. |
Inflate
new Inflate(opts?: ZlibOptions)
Source
Create an Inflate stream with the given opts.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | ZlibOptions | — | Options for the stream and the underlying zlib state. |
DeflateRaw
new DeflateRaw(opts?: ZlibOptions)
Source
Create a DeflateRaw stream with the given opts.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | ZlibOptions | — | Options for the stream and the underlying zlib state. |
InflateRaw
new InflateRaw(opts?: ZlibOptions)
Source
Create an InflateRaw stream with the given opts.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | ZlibOptions | — | Options for the stream and the underlying zlib state. |
Gzip
new Gzip(opts?: ZlibOptions)
Source
Create a Gzip stream with the given opts.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | ZlibOptions | — | Options for the stream and the underlying zlib state. |
Gunzip
new Gunzip(opts?: ZlibOptions)
Source
Create a Gunzip stream with the given opts.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | ZlibOptions | — | Options for the stream and the underlying zlib state. |
Types
ZlibOptions
interface ZlibOptions<S extends ZlibStream = ZlibStream> extends Omit<
TransformOptions<S>,
'flush'
> {
flush?: number
finishFlush?: number
chunkSize?: number
level?: number
windowBits?: number
memLevel?: number
strategy?: number
maxOutputLength?: number
}ZlibCallback
interface ZlibCallback {
(err: Error | null, result: Buffer): void
}Callback for the one-shot asynchronous functions, called with an error or the resulting Buffer.
ZlibFlushCallback
interface ZlibFlushCallback {
(err: Error | null): void
}Callback invoked once a flush() completes.
Classes
ZlibError
Source
class ZlibError {
code: ZlibErrorCode
name: 'ZlibError'
}bare-zlib/constants
Constants and variables
constants
constants: {
Z_NO_FLUSH: number
Z_PARTIAL_FLUSH: number
Z_SYNC_FLUSH: number
Z_FULL_FLUSH: number
Z_FINISH: number
Z_BLOCK: number
Z_TREES: number
Z_FILTERED: number
Z_HUFFMAN_ONLY: number
Z_RLE: number
Z_FIXED: number
Z_DEFAULT_STRATEGY: number
Z_NO_COMPRESSION: number
Z_BEST_SPEED: number
Z_BEST_COMPRESSION: number
Z_DEFAULT_COMPRESSION: number
Z_MIN_CHUNK: number
Z_MAX_CHUNK: number
Z_DEFAULT_CHUNK: number
Z_MIN_MEMLEVEL: number
Z_MAX_MEMLEVEL: number
Z_DEFAULT_MEMLEVEL: number
Z_MIN_LEVEL: number
Z_MAX_LEVEL: number
Z_DEFAULT_LEVEL: number
Z_MIN_WINDOWBITS: number
Z_MAX_WINDOWBITS: number
Z_DEFAULT_WINDOWBITS: number
Z_OK: number
Z_STREAM_END: number
Z_NEED_DICT: number
Z_ERRNO: number
Z_STREAM_ERROR: number
Z_DATA_ERROR: number
Z_MEM_ERROR: number
Z_BUF_ERROR: number
Z_VERSION_ERROR: number
}Zlib-related constants such as flush modes, compression levels, strategies, and chunk/window/memory-level bounds.
bare-zlib/errors
Classes
errors.ZlibError
Source
An error thrown by a zlib operation, carrying a code identifying the underlying zlib failure (such as DATA_ERROR or MEM_ERROR).
See also
- Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.