module documentation
Read and write compressedbuf files, used in NWSync and campaign databases.
Mainly used for NWSync file storage; but also used in sqlite files such as nwsync storage and string/blob compression in campaign sqlite databases.
Binary Format
Field | Size (bytes) | Description |
---|---|---|
Magic | 4 | FileMagic |
Header Version | 4 | Format version (currently always 3) |
Algorithm | 4 | Algorithm |
Uncompressed Size | 4 | Size of the uncompressed data |
Algorithm Version | 4 (if ZLIB/ZSTD) | Version of the compression algorithm (currently always 1) |
Dictionary | 4 (if ZSTD) | Dictionary ID (currently always 0) |
Compressed Data | Variable | The compressed data |
Class |
|
No class docstring; 1/3 constant documented |
Function | read |
Decompresses the given binary file using the specified algorithm. |
Function | write |
Compresses the given data and writes it to the specified file using the specified algorithm. |
Constant | _VERSION |
Undocumented |
Constant | _ZLIB |
Undocumented |
Constant | _ZSTD |
Undocumented |
def read(file:
BinaryIO
, expect_magic: FileMagic | None
= None) -> tuple[ bytes, FileMagic, Algorithm]
:
(source)
¶
Decompresses the given binary file using the specified algorithm.
Parameters | |
file:BinaryIO | The binary file to decompress. |
expectFileMagic | None | The expected file magic. If provided, the file magic read from the file must match this value. |
Returns | |
tuple[ | A tuple containing the decompressed data, the file magic, and the algorithm used. |
Raises | |
ValueError | If the stream is invalid, or the magic number does not match the expected value, or if an unsupported algorithm is encountered. |
Compresses the given data and writes it to the specified file using the specified algorithm.
Parameters | |
file:BinaryIO | The file object to write the compressed data to. |
magic:FileMagic | The file magic to write. |
data:bytes | The data to be compressed. |
alg:Algorithm , optional | The compression algorithm to use. Defaults to Algorithm.ZSTD. |
Raises | |
ValueError | If an unsupported algorithm is specified. |