Compression Structs#

Basic structs#

class caterpillar.py.Compressed(compressor: _Compressor, struct: _ContainsStruct | _StructLike, comp_kwargs: dict | None = None, decomp_kwargs: dict | None = None)[source]#

A class representing a compressed transformer.

Parameters:
  • compressor (_Compressor) – The compression algorithm.

  • length (Union[_ContextLambda, Any]) – The length of the transformer.

decode(parsed: bytes, context: _ContextLike) bytes[source]#

Decompress the input data.

Parameters:
  • parsed (bytes) – The compressed data to be decompressed.

  • context (_ContextLike) – The context information.

Returns:

The decompressed data.

Return type:

bytes

encode(obj: bytes, context: _ContextLike) bytes[source]#

Compress the input data.

Parameters:
  • obj (bytes) – The input data to be compressed.

  • context (_ContextLike) – The context information.

Returns:

The compressed data.

Return type:

bytes

Supported compression types#

caterpillar.py.ZLibCompressed(obj: _ContainsStruct | _StructLike | Callable | int, comp_kwargs: dict | None = None, decomp_kwargs: dict | None = None)[source]#

Create a struct representing zlib compression.

caterpillar.py.Bz2Compressed(obj: _ContainsStruct | _StructLike | Callable | int, comp_kwargs: dict | None = None, decomp_kwargs: dict | None = None)[source]#

Create a struct representing bz2 compression.

caterpillar.py.LZMACompressed(obj: _ContainsStruct | _StructLike | Callable | int, comp_kwargs: dict | None = None, decomp_kwargs: dict | None = None)[source]#

Create a struct representing lzma compression.

caterpillar.py.LZOCompressed(obj: _ContainsStruct | _StructLike | Callable | int, comp_kwargs: dict | None = None, decomp_kwargs: dict | None = None)[source]#

Create a struct representing LZO compression.