Creates a new deflator instance with the specified params. Throws an exception on bad params. See DeflateOptions for the list of supported options.
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)
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.
input data. Strings will be converted to utf8 byte sequence.
0..6 for corresponding Z_NO_FLUSH..Z_TREES modes.
See constants. Skipped or false means Z_NO_FLUSH, true means Z_FINISH.
By default, stores data blocks in the Deflate.chunks property and glues them in Deflate.onEnd. Override this handler if you need another behaviour.
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.
deflate status. Z_OK on success, other if not.
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.
Error message, if Deflate.err is not Z_OK.
InternalchunksChunks of output data, if Deflate.onData not overridden.
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).
Generic JS-style wrapper for zlib calls. If you don't need streaming behaviour, use the simpler functions deflate, deflateRaw and gzip.