Difference between revisions of "Lua API:Bz2"
(Add bzip2 api) |
(98.0 update: Replace with LBPHacker's version) |
||
Line 1: | Line 1: | ||
− | The bz2 | + | The <code>bz2</code> 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. | ||
+ | |||
+ | __TOC__ | ||
== Methods == | == Methods == | ||
=== bz2.compress === | === bz2.compress === | ||
− | |||
− | |||
− | + | Compress data with bzip2 at compression level 9. | |
− | + | <pre>compressedData, errCode, errStr = bz2.compress(data, [maxSize])</pre> | |
+ | * <code>data</code>: string, the data to be compressed | ||
+ | * <code>maxSize</code>: number, upper limit on the length of <code>compressedData</code>; defaults to <code>0</code>, which means no limit | ||
+ | * <code>compressedData</code>: string, the compressed data, or <code>nil</code> on error | ||
+ | * <code>errCode</code>: <code>nil</code>, or one of the following values on error: | ||
+ | ** <code>bz2.COMPRESS_NOMEM</code>: out of memory, TPT will probably crash soon | ||
+ | ** <code>bz2.COMPRESS_LIMIT</code>: the length of <code>compressedData</code> would exceed <code>maxSize</code> | ||
+ | * <code>errStr</code>: <code>nil</code>, or a human-friendly string that explains the error | ||
=== bz2.decompress === | === bz2.decompress === | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | Decompress bzip2-compressed data. | |
− | + | <pre>data, errCode, errStr = bz2.decompress(compressedData, [maxSize])</pre> | |
− | + | * <code>compressedData</code>: string, the compressed data | |
− | + | * <code>maxSize</code>: number, upper limit on the length of <code>data</code>; defaults to <code>0</code>, which means no limit | |
− | + | * <code>data</code>: string, the original data, or <code>nil</code> on error | |
− | ; | + | * <code>errCode</code>: <code>nil</code>, or one of the following values on error: |
− | + | ** <code>bz2.DECOMPRESS_NOMEM</code>: out of memory, TPT will probably crash soon | |
− | + | ** <code>bz2.DECOMPRESS_LIMIT</code>: the length of <code>data</code> would exceed <code>maxSize</code> | |
− | + | ** <code>bz2.DECOMPRESS_TYPE</code>: <code>compressedData</code> is not bzip2-compressed data | |
− | + | ** <code>bz2.DECOMPRESS_BAD</code>: <code>compressedData</code> is otherwise corrupt | |
− | + | ** <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 | |
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Latest revision as of 03:04, 13 March 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.
Contents
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 ofcompressedData
; defaults to0
, which means no limit -
compressedData
: string, the compressed data, ornil
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 ofcompressedData
would exceedmaxSize
-
-
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 ofdata
; defaults to0
, which means no limit -
data
: string, the original data, ornil
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 ofdata
would exceedmaxSize
-
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