pako - v3.0.1
    Preparing search index...

    Class Inflate

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

    Index

    Constructors

    Methods

    Properties

    Constructors

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

      Parameters

      Returns Inflate

      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 chunk

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

      console.log(inflate.result)

    Methods

    • Sends input data to the inflate pipe, generating Inflate.onData calls with new output chunks. Returns true on success. If end of stream is detected, Inflate.onEnd will be called.

      flush_mode is 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 push calls are no-ops and return whether the decode finished successfully. The final outcome is in Inflate.result, Inflate.err and Inflate.msg.

      Parameters

      Returns boolean

      push(chunk, false) // push one of data chunks
      ...
      push(chunk, true) // push last chunk
    • 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)

      Parameters

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

      Parameters

      • chunk: Uint8Array<ArrayBuffer>

        output data.

      Returns void

    Properties

    Error code after inflate finishes. Z_OK on success. Should be checked when broken data is possible.

    msg: string

    Error message, if Inflate.err is not Z_OK.

    ended: boolean

    true once 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.

    chunks: Uint8Array<ArrayBuffer>[]

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

    result: Uint8Array<ArrayBuffer>

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