Difference between revisions of "Lua API:Bz2"

From The Powder Toy
Jump to: navigation, search
(Add bzip2 api)
(No difference)

Revision as of 18:53, 29 December 2022

The bz2 api provides access to our bzip2 library. It can be used for compressing and decompressing blocks of data, such as tpt saves.

Methods

bz2.compress

bz2.compress(sourceData, maxSize)

Accepts source data and returns a string containing the compressed data. maxSize controls the maximum amount of memory to use while compressing the sourceData, and can be 0 to allow unlimited memory.

On success, returns 1 argument - the compressed data

On failure, returns 3 arguments - nil, error code, error string. Error code will be one of the constants documented below

bz2.decompress

bz2.compress(sourceData, maxSize)

Accepts source data and returns a string containing the decompressed data. maxSize controls the maximum amount of memory to use while decompressing the sourceData, and can be 0 to allow unlimited memory.

On success, returns 1 argument - the decompressed data

On failure, returns 3 arguments - nil, error code, error string. Error code will be one of the constants documented below

Constants

compressOk

Compression OK

compressNomem

Compression failed, ran out of memory

compressLimit

Compression failed, maxSize limit exceeded

decompressOk

Decompression OK

decompressNomem

Decompression failed, ran out of memory

decompressLimit

Decompression failed, maxSize limit exceeded

decompressType

Decompression failed, sourceData does not have bzip2 header and is likely not bzip2 data

decompressBad

Decompression failed, sourceData is not valid bzip2 data

decompressEof