Deflate

open class Deflate(options: DeflateOptions = definedExternally)(source)

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

Constructors

Link copied to clipboard
constructor(options: DeflateOptions = definedExternally)

Properties

Link copied to clipboard

Error code after deflate finished. ReturnCode.Z_OK on success. You will not need it in real life, because deflate errors are possible only on wrong options or bad onData / onEnd custom handlers.

Link copied to clipboard
val msg: String?

Error message, if err != ReturnCode.Z_OK

Link copied to clipboard

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

Functions

Link copied to clipboard
open fun onData(chunk: Uint8Array<ArrayBuffer>)

By default, stores data blocks in chunks[] property and glue those in onEnd. Override this handler, if you need another behaviour.

Link copied to clipboard
open fun onEnd(status: ReturnCode)

Called either after you tell inflate that the input stream is complete (Z_FINISH). By default - join collected chunks, free memory and fill results / err properties.

Link copied to clipboard
fun push(data: ArrayBuffer, flush: Flush = definedExternally): Boolean
fun push(data: Uint8Array<*>, flush: Flush = definedExternally): Boolean
fun push(data: String, flush: Flush = definedExternally): Boolean

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