LZSSWDecompressor¶
- class tinycompress.lzssw.LZSSWDecompressor(ringsize=4096, maxmatchlen=16, commonbyte=32)[source]¶
LZSSW decompression implementation.
This decompressor handles data compressed by the LZSSW algorithm, expanding match references back into their original sequences using a ring buffer that mirrors the one used during compression.
The decompressor parameters must match those used for compression: - Ring buffer size controls the maximum back-reference distance - Maximum match length affects how much data a single match can represent - Common byte is used to initialize the ring buffer
Attributes
Whether the decompressor has reached the end of the compressed stream.
Checks if more input data is needed to continue decompression.
Gets any unprocessed data remaining after decompression.
Methods
Initializes a new LZSSW decompressor instance.
Decompresses LZSSW-encoded data.
Flushes any remaining data from the decompressor.
Resets the decompressor to its initial state.
- __init__(ringsize=4096, maxmatchlen=16, commonbyte=32)[source]¶
Initializes a new LZSSW decompressor instance.
- Parameters:
ringsize (
int) – Size of the ring buffer, must match the compressor setting.maxmatchlen (
int) – Maximum match length, must match the compressor setting.commonbyte (
int) – Initial ring buffer fill value, must match compressor setting.
- Raises:
LZSSWException – If any parameters are out of their valid ranges.
- __weakref__¶
list of weak references to the object
- _iter_decode()[source]¶
Generator that implements the main decompression loop.
This internal method drives the LZSSW decompression process: 1. Initializes the ring buffer with the common byte 2. Processes flag bits to determine what follows (literal/match) 3. Copies literal bytes directly to output 4. Expands match references using the ring buffer 5. Maintains the ring buffer for future matches
- Yields:
None on each iteration, accepting compressed data or None/Ellipsis to indicate end of input.
- decompress(data, max_length=-1, /)[source]¶
Decompresses LZSSW-encoded data.
The method feeds compressed data to the decompression generator, which expands match references and copies literal bytes to rebuild the original data.
- Parameters:
data (
Union[bytes,bytearray,memoryview,Iterable[int]]) – Compressed input data to decompress.max_length (
int) – Maximum number of bytes to decompress. Default -1 means no limit.
- Returns:
Decompressed data as bytearray.
- Raises:
LZSSWException – If the decompressor has been flushed.
- property eof: bool¶
Whether the decompressor has reached the end of the compressed stream.
- Returns:
True if all input has been processed and flushed, False otherwise.
- flush()[source]¶
Flushes any remaining data from the decompressor.
This method finalizes the decompression process by: 1. Processing any remaining input data 2. Signaling EOF to the decoder 3. Returning any remaining decompressed data
- Returns:
Any remaining decompressed data, or empty bytearray if already flushed.
- property needs_input: bool¶
Checks if more input data is needed to continue decompression.
This property indicates whether the decompressor needs more input data to make progress. It returns False only when the end of the compressed stream has been reached.
- Returns:
True if more input data is needed, False if decompression is complete.
- reset()[source]¶
Resets the decompressor to its initial state.
Clears all internal buffers and state variables, allowing the decompressor to be reused for a new decompression task. This includes: - Clearing output and ahead buffers - Resetting state variables - Creating a new decoder generator
- property unused_data: bytearray¶
Gets any unprocessed data remaining after decompression.
Returns any data that was found after the end of the compressed stream or None if decompression is not yet complete.
- Returns:
Remaining unprocessed data if eof is True, empty bytearray otherwise.