pako
- Version 3.0.1
- Published
- 2.49 MB
- No dependencies
- (MIT AND Zlib) license
Install
npm i pakoyarn add pakopnpm add pakoOverview
zlib port to javascript - fast, modularized, with browser support
Index
Variables
Functions
- deflate()
- deflateRaw()
- gzip()
- inflate()
- inflateRaw()
- ungzip()
- zlibDeflate()
- zlibDeflateEnd()
- zlibDeflateInit()
- zlibDeflateInit2()
- zlibDeflateReset()
- zlibDeflateResetKeep()
- zlibDeflateSetDictionary()
- zlibDeflateSetHeader()
- zlibInflate()
- zlibInflateEnd()
- zlibInflateGetHeader()
- zlibInflateInit()
- zlibInflateInit2()
- zlibInflateReset()
- zlibInflateReset2()
- zlibInflateResetKeep()
- zlibInflateSetDictionary()
Classes
Interfaces
Type Aliases
Variables
variable Z_BLOCK
const Z_BLOCK: number;constants
variable Z_BUF_ERROR
const Z_BUF_ERROR: number;constants
variable Z_DATA_ERROR
const Z_DATA_ERROR: number;constants
variable Z_ERRNO
const Z_ERRNO: number;constants
variable Z_FINISH
const Z_FINISH: number;constants
variable Z_FULL_FLUSH
const Z_FULL_FLUSH: number;constants
variable Z_MEM_ERROR
const Z_MEM_ERROR: number;constants
variable Z_NEED_DICT
const Z_NEED_DICT: number;constants
variable Z_NO_FLUSH
const Z_NO_FLUSH: number;constants
variable Z_OK
const Z_OK: number;constants
variable Z_PARTIAL_FLUSH
const Z_PARTIAL_FLUSH: number;constants
variable Z_STREAM_END
const Z_STREAM_END: number;constants
variable Z_STREAM_ERROR
const Z_STREAM_ERROR: number;constants
variable Z_SYNC_FLUSH
const Z_SYNC_FLUSH: number;constants
variable Z_TREES
const Z_TREES: number;constants
Functions
function deflate
deflate: (input: DeflateInput, options?: DeflateOptions) => any;Compress
datawith deflate algorithm andoptions. See DeflateOptions for the list of supported options.Example 1
import { deflate } from 'pako'const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9])console.log(deflate(data))
function deflateRaw
deflateRaw: (input: DeflateInput, options?: DeflateOptions) => any;The same as deflate, but creates raw data without a wrapper (header and adler32 crc).
function gzip
gzip: (input: DeflateInput, options?: DeflateOptions) => any;The same as deflate, but creates a gzip wrapper instead of a deflate one.
function inflate
inflate: <O extends InflateOptions & { toText?: boolean }>( input: InflateInput, options?: O) => O extends { toText: true } ? string : Uint8Array<ArrayBuffer>;One-shot inflate decompress. Autodetects
gzip/zlibformat via the wrapper header — so ungzip is just a convenience alias of this function. See InflateOptions for zlib options. SettoText: trueto decode the result as UTF-8 text.Example 1
import { deflate, inflate } from 'pako'const input = deflate(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]))let outputtry {output = inflate(input)} catch (err) {console.log(err)}
function inflateRaw
inflateRaw: <O extends InflateOptions & { toText?: boolean }>( input: InflateInput, options?: O) => O extends { toText: true } ? string : Uint8Array<ArrayBuffer>;The same as inflate, but consumes raw data without a wrapper (header and adler32 crc).
function ungzip
ungzip: <O extends InflateOptions & { toText?: boolean }>( input: InflateInput, options?: O) => O extends { toText: true } ? string : Uint8Array<ArrayBuffer>;One-shot inflate decompress. Autodetects
gzip/zlibformat via the wrapper header — so ungzip is just a convenience alias of this function. See InflateOptions for zlib options. SettoText: trueto decode the result as UTF-8 text.Example 1
import { deflate, inflate } from 'pako'const input = deflate(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]))let outputtry {output = inflate(input)} catch (err) {console.log(err)}
function zlibDeflate
zlibDeflate: (strm: ZStream, flush: Z_FlushMode) => Z_CallStatus;zlib
function zlibDeflateEnd
zlibDeflateEnd: (strm: ZStream) => Z_CallStatus;zlib
function zlibDeflateInit
zlibDeflateInit: (strm: ZStream, level: number) => Z_CallStatus;zlib
function zlibDeflateInit2
zlibDeflateInit2: ( strm: ZStream, level: number, method: number, windowBits: number, memLevel: number, strategy: number, legacyHash?: boolean) => Z_CallStatus;zlib
function zlibDeflateReset
zlibDeflateReset: (strm: ZStream) => Z_CallStatus;zlib
function zlibDeflateResetKeep
zlibDeflateResetKeep: (strm: ZStream) => Z_CallStatus;zlib
function zlibDeflateSetDictionary
zlibDeflateSetDictionary: ( strm: ZStream, dictionary: Uint8Array) => Z_CallStatus;zlib
function zlibDeflateSetHeader
zlibDeflateSetHeader: (strm: ZStream, head: GZheader) => Z_CallStatus;zlib
function zlibInflate
zlibInflate: (strm: ZStream, flush: Z_FlushMode) => Z_CallStatus;zlib
function zlibInflateEnd
zlibInflateEnd: (strm: ZStream) => Z_CallStatus;zlib
function zlibInflateGetHeader
zlibInflateGetHeader: (strm: ZStream, head: GZheader) => Z_CallStatus;zlib
function zlibInflateInit
zlibInflateInit: (strm: ZStream) => Z_CallStatus;zlib
function zlibInflateInit2
zlibInflateInit2: (strm: ZStream, windowBits: number) => Z_CallStatus;zlib
function zlibInflateReset
zlibInflateReset: (strm: ZStream) => Z_CallStatus;zlib
function zlibInflateReset2
zlibInflateReset2: (strm: ZStream, windowBits: number) => Z_CallStatus;zlib
function zlibInflateResetKeep
zlibInflateResetKeep: (strm: ZStream) => Z_CallStatus;zlib
function zlibInflateSetDictionary
zlibInflateSetDictionary: ( strm: ZStream, dictionary: Uint8Array) => Z_CallStatus;zlib
Classes
class Deflate
class Deflate {}Generic JS-style wrapper for zlib calls. If you don't need streaming behaviour, use the simpler functions deflate, deflateRaw and gzip.
constructor
constructor(options?: DeflateOptions);Creates a new deflator instance with the specified params. Throws an exception on bad params. See DeflateOptions for the list of supported options.
Example 1
import { Deflate } from 'pako'const chunk1 = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9])const chunk2 = new Uint8Array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19])const deflate = new Deflate({ level: 3 })deflate.push(chunk1, false)deflate.push(chunk2, true) // true -> last chunkif (deflate.err) throw new Error(deflate.err)console.log(deflate.result)
property err
err: Z_CallStatus;Error code after deflate finishes. Z_OK on success. You will not need it in real life, because deflate errors are possible only on wrong options or bad custom
onData/onEndhandlers.
property msg
msg: string;Error message, if Deflate.err is not Z_OK.
property result
result: any;Compressed result, generated by default Deflate.onData and Deflate.onEnd handlers. Filled after you push last chunk (call Deflate.push with Z_FINISH /
trueparam).
method onData
onData: (chunk: any) => void;By default, stores data blocks in the Deflate.chunks property and glues them in Deflate.onEnd. Override this handler if you need another behaviour.
method onEnd
onEnd: (status: Z_CallStatus) => void;Called once after you tell deflate that the input stream is complete (Z_FINISH). By default, joins the collected Deflate.chunks into the Deflate.result property.
Parameter status
deflate status. Z_OK on success, other if not.
method onStart
onStart: (strm: ZStream) => void;Called once before the first low-level deflate call.
method push
push: (data: DeflateInput, flush_mode?: Z_FlushMode | boolean) => boolean;Sends input data to the deflate pipe, generating Deflate.onData calls with new compressed chunks. Returns
trueon success. The last data block must haveflush_modeZ_FINISH (ortrue). That will flush the internal pending buffers and call Deflate.onEnd.On failure, calls Deflate.onEnd with the error code and returns false.
Parameter data
input data. Strings will be converted to utf8 byte sequence.
Parameter flush_mode
0..6 for corresponding Z_NO_FLUSH..Z_TREES modes. See constants. Skipped or
falsemeans Z_NO_FLUSH,truemeans Z_FINISH.Example 1
push(chunk, false) // push one of data chunks...push(chunk, true) // push last chunk
class GZheader
class GZheader {}zlib
class Inflate
class Inflate {}Generic JS-style wrapper for zlib calls. If you don't need streaming behaviour, use the simpler functions inflate and inflateRaw.
constructor
constructor(options?: InflateOptions);Creates a new inflator instance with the specified params. Throws an exception on bad params. See InflateOptions for the list of supported options.
By default, when no options are set, the deflate/gzip data format is autodetected via the wrapper header.
Example 1
import { Inflate } from 'pako'const chunk1 = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9])const chunk2 = new Uint8Array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19])const inflate = new Inflate({ level: 3 })inflate.push(chunk1, false)inflate.push(chunk2, true) // true -> last chunkif (inflate.err) throw new Error(inflate.err)console.log(inflate.result)
property ended
ended: boolean;trueonce the compressed stream has ended. A stream may end before the caller's data does (trailing bytes), so check this to know when to stop pushing - further Inflate.push calls are no-ops.
property err
err: Z_CallStatus;Error code after inflate finishes. Z_OK on success. Should be checked when broken data is possible.
property msg
msg: string;Error message, if Inflate.err is not Z_OK.
property result
result: any;Uncompressed result, generated by default Inflate.onData and Inflate.onEnd handlers. Filled after you push last chunk (call Inflate.push with Z_FINISH /
trueparam).
method onData
onData: (chunk: any) => void;By default, stores data blocks in the Inflate.chunks property and glues them in Inflate.onEnd. Override this handler if you need another behaviour.
Parameter chunk
output data.
method onEnd
onEnd: (status: Z_CallStatus) => void;Called after you tell inflate that the input stream is complete (Z_FINISH). By default, joins the collected Inflate.chunks, frees memory and fills the Inflate.result property.
Parameter status
inflate status. Z_OK on success, other if not.
method onStart
onStart: (strm: ZStream) => void;Called once before the first low-level inflate call.
Override this handler to attach low-level inflate state, for example to read gzip header metadata:
import { Inflate, GZheader, zlibInflateGetHeader } from 'pako'const inflator = new Inflate()inflator.onStart = function (strm) {this.header = new GZheader()zlibInflateGetHeader(strm, this.header)}inflator.push(data, true)console.log(inflator.header.name)
method push
push: (data: InflateInput, flush_mode?: Z_FlushMode | boolean) => boolean;Sends input data to the inflate pipe, generating Inflate.onData calls with new output chunks. Returns
trueon success. If end of stream is detected, Inflate.onEnd will be called.flush_modeis not needed for normal operation, because end of stream is detected automatically. Pass Z_SYNC_FLUSH to force the decoder to emit all currently available output — handy when you need to decode data frame-by-frame from a long-running stream.On failure, calls Inflate.onEnd with the error code and returns false.
Once the stream has ended (a compressed stream may end before your data does), further
pushcalls are no-ops and return whether the decode finished successfully. The final outcome is in Inflate.result, Inflate.err and Inflate.msg.Parameter flush_mode
0..6 for corresponding Z_NO_FLUSH..Z_TREES flush modes. See constants. Skipped or
falsemeans Z_NO_FLUSH,truemeans Z_FINISH.Example 1
push(chunk, false) // push one of data chunks...push(chunk, true) // push last chunk
class ZStream
class ZStream {}zlib
property adler
adler: number;property avail_in
avail_in: number;property avail_out
avail_out: number;property data_type
data_type: number;property input
input: Uint8Array;property msg
msg: string;property next_in
next_in: number;property next_out
next_out: number;property output
output: any;property state
state: any;property total_in
total_in: number;property total_out
total_out: number;Interfaces
interface DeflateOptions
interface DeflateOptions {}property chunkSize
chunkSize?: number;Size of generated data chunks (16K by default). Extensions
property dictionary
dictionary?: Uint8Array | ArrayBuffer;Initial dictionary. See the [zlib manual](http://zlib.net/manual.html#Advanced) for more information. zlib options
property gzip
gzip?: boolean;Create gzip wrapper. Extensions
property legacyHash
legacyHash?: boolean;Set to
trueto use the classic zlib hash, which matches canonical zlib output byte-for-byte. The defaultfalseuses the faster ANZAC++ hash, which matches recent (chromium) node.js output instead. Extensions
property level
level?: number;Compression level. See the [zlib manual](http://zlib.net/manual.html#Advanced) for more information. zlib options
property memLevel
memLevel?: number;Memory level. See the [zlib manual](http://zlib.net/manual.html#Advanced) for more information. zlib options
property raw
raw?: boolean;Do raw deflate. Say that we work with raw stream, if you don't wish to specify negative
windowBitsimplicitly. Extensions
property strategy
strategy?: number;Compression strategy. See the [zlib manual](http://zlib.net/manual.html#Advanced) for more information. zlib options
property windowBits
windowBits?: number;Window size. See the [zlib manual](http://zlib.net/manual.html#Advanced) for more information. zlib options
interface InflateOptions
interface InflateOptions {}property chunkSize
chunkSize?: number;Size of generated data chunks (64K by default). Extensions
property dictionary
dictionary?: Uint8Array | ArrayBuffer;Initial dictionary. See the [zlib manual](http://zlib.net/manual.html#Advanced) for more information. zlib options
property raw
raw?: boolean;Do raw inflate. Say that we work with raw stream, if you don't wish to specify negative
windowBitsimplicitly. Extensions
property windowBits
windowBits?: number;Window size. See the [zlib manual](http://zlib.net/manual.html#Advanced) for more information. zlib options
Type Aliases
type Z_CallStatus
type Z_CallStatus = | typeof Z_OK | typeof Z_STREAM_END | typeof Z_NEED_DICT | typeof Z_ERRNO | typeof Z_STREAM_ERROR | typeof Z_DATA_ERROR | typeof Z_MEM_ERROR | typeof Z_BUF_ERROR;constants
type Z_FlushMode
type Z_FlushMode = | typeof Z_NO_FLUSH | typeof Z_PARTIAL_FLUSH | typeof Z_SYNC_FLUSH | typeof Z_FULL_FLUSH | typeof Z_FINISH | typeof Z_BLOCK | typeof Z_TREES;constants
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (10)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/pako.
- Markdown[](https://www.jsdocs.io/package/pako)
- HTML<a href="https://www.jsdocs.io/package/pako"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3619 ms. - Missing or incorrect documentation? Open an issue for this package.
