Difference between revisions of "Lua API:Bz2"

From The Powder Toy
Jump to: navigation, search
(98.0 update: Replace with LBPHacker's version)
m (Add to Lua category)
 
Line 37: Line 37:
 
** <code>bz2.DECOMPRESS_EOF</code>: <code>compressedData</code> contains data beyond the end of the bzip2 stream
 
** <code>bz2.DECOMPRESS_EOF</code>: <code>compressedData</code> contains data beyond the end of the bzip2 stream
 
* <code>errStr</code>: <code>nil</code>, or a human-friendly string that explains the error
 
* <code>errStr</code>: <code>nil</code>, or a human-friendly string that explains the error
 +
 +
[[Category:Lua]]

Latest revision as of 05:15, 15 December 2024

The bz2 API provides access to the bzip2 library TPT bundles. It can be used for compressing and decompressing blocks of data, such as TPT saves.

Only one-shot functionality is exposed because streaming functionality is only useful for tasks that are beyond the scope of this API.

Unless stated otherwise, all functions raise errors if supplied with parameters that disagree with their descriptions.

Methods

bz2.compress

Compress data with bzip2 at compression level 9.

compressedData, errCode, errStr = bz2.compress(data, [maxSize])
  • data: string, the data to be compressed
  • maxSize: number, upper limit on the length of compressedData; defaults to 0, which means no limit
  • compressedData: string, the compressed data, or nil on error
  • errCode: nil, or one of the following values on error:
    • bz2.COMPRESS_NOMEM: out of memory, TPT will probably crash soon
    • bz2.COMPRESS_LIMIT: the length of compressedData would exceed maxSize
  • errStr: nil, or a human-friendly string that explains the error

bz2.decompress

Decompress bzip2-compressed data.

data, errCode, errStr = bz2.decompress(compressedData, [maxSize])
  • compressedData: string, the compressed data
  • maxSize: number, upper limit on the length of data; defaults to 0, which means no limit
  • data: string, the original data, or nil on error
  • errCode: nil, or one of the following values on error:
    • bz2.DECOMPRESS_NOMEM: out of memory, TPT will probably crash soon
    • bz2.DECOMPRESS_LIMIT: the length of data would exceed maxSize
    • bz2.DECOMPRESS_TYPE: compressedData is not bzip2-compressed data
    • bz2.DECOMPRESS_BAD: compressedData is otherwise corrupt
    • bz2.DECOMPRESS_EOF: compressedData contains data beyond the end of the bzip2 stream
  • errStr: nil, or a human-friendly string that explains the error