pako - v3.0.1
    Preparing search index...

    Class Deflate

    Generic JS-style wrapper for zlib calls. If you don't need streaming behaviour, use the simpler functions deflate, deflateRaw and gzip.

    Index

    Constructors

    Methods

    Properties

    Constructors

    • Creates a new deflator instance with the specified params. Throws an exception on bad params. See DeflateOptions for the list of supported options.

      Parameters

      Returns Deflate

      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 chunk

      if (deflate.err) throw new Error(deflate.err)

      console.log(deflate.result)

    Methods

    • Sends input data to the deflate pipe, generating Deflate.onData calls with new compressed chunks. Returns true on success. The last data block must have flush_mode Z_FINISH (or true). That will flush the internal pending buffers and call Deflate.onEnd.

      On failure, calls Deflate.onEnd with the error code and returns false.

      Parameters

      • data: string | ArrayBuffer | Uint8Array<ArrayBufferLike>

        input data. Strings will be converted to utf8 byte sequence.

      • flush_mode: boolean | Z_FlushMode = false

        0..6 for corresponding Z_NO_FLUSH..Z_TREES modes. See constants. Skipped or false means Z_NO_FLUSH, true means Z_FINISH.

      Returns boolean

      push(chunk, false) // push one of data chunks
      ...
      push(chunk, true) // push last chunk
    • Called once before the first low-level deflate call.

      Parameters

      Returns 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.

      Parameters

      • chunk: Uint8Array<ArrayBuffer>

      Returns void

    Properties

    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 / onEnd handlers.

    msg: string

    Error message, if Deflate.err is not Z_OK.

    chunks: Uint8Array<ArrayBuffer>[]

    Chunks of output data, if Deflate.onData not overridden.

    result: Uint8Array<ArrayBuffer>

    Compressed result, generated by default Deflate.onData and Deflate.onEnd handlers. Filled after you push last chunk (call Deflate.push with Z_FINISH / true param).