LogoPear Docs

bare-zlib

Stream-based zlib bindings for JavaScript

stable

bare-zlib — Stream-based zlib bindings for JavaScript. It is a native addon.

Mirrors the Node.js zlib module.

npm i bare-zlib

API

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
}
Source

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

ParameterTypeDefaultDescription
opts?ZlibOptionsOptions 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

ParameterTypeDefaultDescription
opts?ZlibOptionsOptions 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

ParameterTypeDefaultDescription
opts?ZlibOptionsOptions 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

ParameterTypeDefaultDescription
opts?ZlibOptionsOptions 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

ParameterTypeDefaultDescription
opts?ZlibOptionsOptions 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

ParameterTypeDefaultDescription
opts?ZlibOptionsOptions 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): void

Parameters

ParameterTypeDefaultDescription
bufferZlibInputThe data to compress.
optsZlibOptionsThe zlib options to apply for this operation.
cbZlibCallbackCalled 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): void

Parameters

ParameterTypeDefaultDescription
bufferZlibInputThe data to compress.
optsZlibOptionsThe zlib options to apply for this operation.
cbZlibCallbackCalled 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

ParameterTypeDefaultDescription
bufferZlibInputThe data to compress; a string is converted to a Buffer.
opts?ZlibOptionsThe zlib options to apply for this operation.

Throws

  • LIMIT_EXCEEDED — the output exceeded maxOutputLength.
  • ZlibError — the underlying zlib operation failed; code identifies the failure.

Zlib.deflateSync(buffer: ZlibInput, opts?: ZlibOptions): Buffer

Source

Synchronously compress buffer with deflate and return the resulting Buffer.

Parameters

ParameterTypeDefaultDescription
bufferZlibInputThe data to compress; a string is converted to a Buffer.
opts?ZlibOptionsThe zlib options to apply for this operation.

Throws

  • LIMIT_EXCEEDED — the output exceeded maxOutputLength.
  • ZlibError — the underlying zlib operation failed; code identifies 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): void

Parameters

ParameterTypeDefaultDescription
bufferZlibInputThe data to decompress.
optsZlibOptionsThe zlib options to apply for this operation.
cbZlibCallbackCalled 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

ParameterTypeDefaultDescription
bufferZlibInputThe data to decompress; a string is converted to a Buffer.
opts?ZlibOptionsThe zlib options to apply for this operation.

Throws

  • LIMIT_EXCEEDED — the output exceeded maxOutputLength.
  • ZlibError — the underlying zlib operation failed; code (such as DATA_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): void

Parameters

ParameterTypeDefaultDescription
bufferZlibInputThe data to compress.
optsZlibOptionsThe zlib options to apply for this operation.
cbZlibCallbackCalled 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

ParameterTypeDefaultDescription
bufferZlibInputThe data to compress; a string is converted to a Buffer.
opts?ZlibOptionsThe zlib options to apply for this operation.

Throws

  • LIMIT_EXCEEDED — the output exceeded maxOutputLength.
  • ZlibError — the underlying zlib operation failed; code identifies 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): void

Parameters

ParameterTypeDefaultDescription
bufferZlibInputThe data to decompress.
optsZlibOptionsThe zlib options to apply for this operation.
cbZlibCallbackCalled 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): void

Parameters

ParameterTypeDefaultDescription
bufferZlibInputThe data to decompress.
optsZlibOptionsThe zlib options to apply for this operation.
cbZlibCallbackCalled 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

ParameterTypeDefaultDescription
bufferZlibInputThe data to decompress; a string is converted to a Buffer.
opts?ZlibOptionsThe zlib options to apply for this operation.

Throws

  • LIMIT_EXCEEDED — the output exceeded maxOutputLength.
  • ZlibError — the underlying zlib operation failed; code (such as DATA_ERROR) identifies the failure.

Zlib.inflateSync(buffer: ZlibInput, opts?: ZlibOptions): Buffer

Source

Synchronously decompress buffer with inflate and return the resulting Buffer.

Parameters

ParameterTypeDefaultDescription
bufferZlibInputThe data to decompress; a string is converted to a Buffer.
opts?ZlibOptionsThe zlib options to apply for this operation.

Throws

  • LIMIT_EXCEEDED — the output exceeded maxOutputLength.
  • ZlibError — the underlying zlib operation failed; code (such as DATA_ERROR) identifies the failure.

Zlib.ZlibInput

type ZlibInput = string | Buffer | Uint8Array
Source

The 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

ParameterTypeDefaultDescription
mode?numberThe flush mode, from constants (default Z_FULL_FLUSH).
cb?ZlibFlushCallbackCalled 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

ParameterTypeDefaultDescription
opts?ZlibOptionsOptions for the stream and the underlying zlib state.

Inflate

new Inflate(opts?: ZlibOptions)

Source

Create an Inflate stream with the given opts.

Parameters

ParameterTypeDefaultDescription
opts?ZlibOptionsOptions for the stream and the underlying zlib state.

DeflateRaw

new DeflateRaw(opts?: ZlibOptions)

Source

Create a DeflateRaw stream with the given opts.

Parameters

ParameterTypeDefaultDescription
opts?ZlibOptionsOptions for the stream and the underlying zlib state.

InflateRaw

new InflateRaw(opts?: ZlibOptions)

Source

Create an InflateRaw stream with the given opts.

Parameters

ParameterTypeDefaultDescription
opts?ZlibOptionsOptions for the stream and the underlying zlib state.

Gzip

new Gzip(opts?: ZlibOptions)

Source

Create a Gzip stream with the given opts.

Parameters

ParameterTypeDefaultDescription
opts?ZlibOptionsOptions for the stream and the underlying zlib state.

Gunzip

new Gunzip(opts?: ZlibOptions)

Source

Create a Gunzip stream with the given opts.

Parameters

ParameterTypeDefaultDescription
opts?ZlibOptionsOptions 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
}
Source

ZlibCallback

interface ZlibCallback {
  (err: Error | null, result: Buffer): void
}
Source

Callback for the one-shot asynchronous functions, called with an error or the resulting Buffer.

ZlibFlushCallback

interface ZlibFlushCallback {
  (err: Error | null): void
}
Source

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
}
Source

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

On this page

API
Zlib
Zlib.constants
Zlib.createDeflate(opts?: ZlibOptions): Deflate
Zlib.createDeflateRaw(opts?: ZlibOptions): DeflateRaw
Zlib.createGunzip(opts?: ZlibOptions): Gunzip
Zlib.createGzip(opts?: ZlibOptions): Gzip
Zlib.createInflate(opts?: ZlibOptions): Inflate
Zlib.createInflateRaw(opts?: ZlibOptions): InflateRaw
Zlib.deflate(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Zlib.deflateRaw(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Zlib.deflateRawSync(buffer: ZlibInput, opts?: ZlibOptions): Buffer
Zlib.deflateSync(buffer: ZlibInput, opts?: ZlibOptions): Buffer
Zlib.gunzip(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Zlib.gunzipSync(buffer: ZlibInput, opts?: ZlibOptions): Buffer
Zlib.gzip(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Zlib.gzipSync(buffer: ZlibInput, opts?: ZlibOptions): Buffer
Zlib.inflate(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Zlib.inflateRaw(buffer: ZlibInput, opts: ZlibOptions, cb: ZlibCallback): void
Zlib.inflateRawSync(buffer: ZlibInput, opts?: ZlibOptions): Buffer
Zlib.inflateSync(buffer: ZlibInput, opts?: ZlibOptions): Buffer
Zlib.ZlibInput
ZlibStream
flush(mode?: number, cb?: ZlibFlushCallback): Promise<void>
reset(): void
Deflate
new Deflate(opts?: ZlibOptions)
Inflate
new Inflate(opts?: ZlibOptions)
DeflateRaw
new DeflateRaw(opts?: ZlibOptions)
InflateRaw
new InflateRaw(opts?: ZlibOptions)
Gzip
new Gzip(opts?: ZlibOptions)
Gunzip
new Gunzip(opts?: ZlibOptions)
Types
ZlibOptions
ZlibCallback
ZlibFlushCallback
Classes
ZlibError
bare-zlib/constants
Constants and variables
constants
bare-zlib/errors
Classes
errors.ZlibError
See also