4.8.3. Compression Structs#
4.8.3.1. Basic structs#
- class caterpillar.fields.Compressed(compressor, struct, comp_kwargs=None, decomp_kwargs=None)[source]#
A transformer class for handling compression and decompression of data.
This class takes a compression algorithm that implements the _Compressor protocol and applies it to the data for compression or decompression operations. It allows for additional customization through the comp_kwargs and decomp_kwargs parameters.
- Parameters:
compressor (_Compressor) – The compression algorithm that implements the _Compressor protocol.
struct (Union[_ContainsStruct, _StructLike]) – The struct to be compressed or decompressed, should implement _ContainsStruct or _StructLike.
comp_kwargs (Optional[dict]) – Optional keyword arguments for the compression method.
decomp_kwargs (Optional[dict]) – Optional keyword arguments for the decompression method.
- encode(obj: bytes, context) bytes[source]#
Compress the input data using the provided compressor.
- Parameters:
obj (bytes) – The data to be compressed.
context (_ContextLike) – Context information for compression (e.g., field-specific metadata).
- Returns:
The compressed data.
- Return type:
bytes
- decode(parsed: bytes, context) bytes[source]#
Decompress the input data using the provided compressor.
- Parameters:
parsed (bytes) – The compressed data to be decompressed.
context (_ContextLike) – Context information for decompression (e.g., field-specific metadata).
- Returns:
The decompressed data.
- Return type:
bytes
4.8.3.2. Supported compression types#
- caterpillar.fields.ZLibCompressed(obj, comp_kwargs=None, decomp_kwargs=None)[source]#
Create a struct representing zlib compression.
- caterpillar.fields.Bz2Compressed(obj, comp_kwargs=None, decomp_kwargs=None)[source]#
Create a struct representing bz2 compression.