dreamworkAPI
Ctrl K
GitHub
libraryDocs / deflate

deflate

librarysharedmenusource

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

Functions

deflate.compressCompresses a string into a raw DEFLATE stream.
deflate.decompressDecompresses a raw DEFLATE stream.

#deflate.compress

sharedmenunodiscardsource
function deflate.compress(raw_data: string, options?: deflate.Options): string

Compresses a string into a raw DEFLATE stream.

Parameters
NameTypeDescription
raw_datastringThe string to compress.
optionsoptionaldeflate.OptionsThe compression options.
Returns
TypeNameDescription
stringcompressed_dataThe compressed string.

#deflate.decompress

sharedmenunodiscardsource
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
NameTypeDescription
compressed_datastringThe DEFLATE stream to decompress.
dictionaryoptionalstringThe preset dictionary the data was compressed with.
start_positionoptionalintegerThe position of the stream in the string, 1 by default.
Returns
TypeNameDescription
stringdecompressed_dataThe decompressed string.
integerend_positionThe position of the first byte after the stream.
Generated from the dreamwork meta branch.