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 Algorithm 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_VERSION Undocumented
Constant _ZSTD_VERSION 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:BinaryIOThe binary file to decompress.
expect_magic:FileMagic | NoneThe expected file magic. If provided, the file magic read from the file must match this value.
Returns
tuple[bytes, FileMagic, Algorithm]A tuple containing the decompressed data, the file magic, and the algorithm used.
Raises
ValueErrorIf the stream is invalid, or the magic number does not match the expected value, or if an unsupported algorithm is encountered.
def write(file: BinaryIO, magic: FileMagic, data: bytes, alg=Algorithm.ZSTD): (source)

Compresses the given data and writes it to the specified file using the specified algorithm.

Parameters
file:BinaryIOThe file object to write the compressed data to.
magic:FileMagicThe file magic to write.
data:bytesThe data to be compressed.
alg:Algorithm, optionalThe compression algorithm to use. Defaults to Algorithm.ZSTD.
Raises
ValueErrorIf an unsupported algorithm is specified.
_VERSION: int = (source)

Undocumented

Value
3
_ZLIB_VERSION: int = (source)

Undocumented

Value
1
_ZSTD_VERSION: int = (source)

Undocumented

Value
1