BaseCompressor

class tinycompress.base.BaseCompressor[source]

Abstract base class for implementing data compressors.

This class defines the interface that all compressor classes must implement. Compressors process input data in chunks and can be flushed to get any remaining compressed data.

Attributes

eof

Whether the compressor has finished processing all input.

Methods

__init__

compress

Compresses the given data.

flush

Flushes any remaining data from the compressor.

reset

Resets the compressor to its initial state.

__weakref__

list of weak references to the object

abstractmethod compress(data)[source]

Compresses the given data.

Parameters:

data (Union[bytes, bytearray, memoryview, Iterable[int]]) – Input data to compress, can be bytes, bytearray, memoryview or any iterable of integers in range(256).

Returns:

The compressed data as bytes or bytearray.

Raises:

Exception – If the compressor has been flushed.

abstract property eof: bool

Whether the compressor has finished processing all input.

Returns:

True if the compressor has been flushed and can no longer accept data, False if it can still process more input.

abstractmethod flush()[source]

Flushes any remaining data from the compressor.

This method finalizes the compression process by returning any remaining compressed data that may be buffered internally.

Returns:

Any remaining compressed data as bytes or bytearray.

Raises:

Exception – If the compressor has already been flushed.

abstractmethod reset()[source]

Resets the compressor to its initial state.

This allows reusing the same compressor instance for multiple compression tasks by clearing any internal state and buffers.