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.
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)
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.
0..6 for corresponding Z_NO_FLUSH..Z_TREES
flush modes. See constants. Skipped or false means Z_NO_FLUSH,
true means Z_FINISH.
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)
By default, stores data blocks in the Inflate.chunks property and glues them in Inflate.onEnd. Override this handler if you need another behaviour.
output data.
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.
inflate status. Z_OK on success, other if not.
Error code after inflate finishes. Z_OK on success. Should be checked when broken data is possible.
Error message, if Inflate.err is not Z_OK.
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.
InternalchunksChunks of output data, if Inflate.onData not overridden.
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).
Generic JS-style wrapper for zlib calls. If you don't need streaming behaviour, use the simpler functions inflate and inflateRaw.