deflate
DEFLATE is a lossless compression format that combines LZ77 and Huffman coding, it is used by zlib, gzip, PNG and ZIP.
Produces and consumes raw DEFLATE streams (no header, no checksum) compatible with zlib's deflate / inflate with negative window bits, see zlib for the zlib format.
Classes & types
class
deflate.Compressor
The DEFLATE stream compressor object.
class
deflate.Decompressor
The DEFLATE stream decompressor object.
type
deflate.InflateState
type
deflate.InflateStream
type
deflate.Options
Options of deflate.compress and zlib.compress, every field is optional.
type
deflate.State
type
deflate.Stream
type
deflate.Writer
Functions
deflate.compress | Compresses a string into a raw DEFLATE stream. |
deflate.decompress | Decompresses a raw DEFLATE stream. |
#deflate.compress
function deflate.compress(raw_data: string, options?: deflate.Options): string
Compresses a string into a raw DEFLATE stream.
Parameters
| Name | Type | Description |
|---|---|---|
raw_data | string | The string to compress. |
optionsoptional | deflate.Options | The compression options. |
Returns
| Type | Name | Description |
|---|---|---|
string | compressed_data | The compressed string. |
#deflate.decompress
function deflate.decompress(compressed_data: string, dictionary?: string, start_position?: integer): string, integer
Decompresses a raw DEFLATE stream.
Throws an error on malformed or truncated data; call via pcall() when processing untrusted input.
The stream may be followed by other data (like the zlib or gzip trailer), the second return value is the position right after the stream.
Parameters
| Name | Type | Description |
|---|---|---|
compressed_data | string | The DEFLATE stream to decompress. |
dictionaryoptional | string | The preset dictionary the data was compressed with. |
start_positionoptional | integer | The position of the stream in the string, 1 by default. |
Returns
| Type | Name | Description |
|---|---|---|
string | decompressed_data | The decompressed string. |
integer | end_position | The position of the first byte after the stream. |