Skip to content

Usage#

The following gist is to help you getting started using this library

from lzallright import EResult, InputNotConsumed, LZOCompressor

data = b"Hello World! " * 100

compressor = LZOCompressor()  # (1)!
compressed = compressor.compress(data)  # (2)!

decompressed = LZOCompressor.decompress(compressed)  # (3)!
assert decompressed == data

decompressed = LZOCompressor.decompress(compressed, output_size_hint=len(data))  # (4)!
assert decompressed == data

try:
    LZOCompressor.decompress(compressed + b"trailing garbage")
except InputNotConsumed as e:  # (5)!
    reason, decompressed = e.args
    assert reason == EResult.InputNotConsumed
    assert decompressed == data
  1. Create a compressor. Reuse the instance to reuse its working memory across calls
  2. Compress any object implementing the buffer protocol (bytes, bytearray, memoryview, ...)
  3. Decompression is a static method, no instance needed
  4. Pass the expected size, if known, to avoid reallocating the output buffer
  5. Trailing data after a valid stream raises InputNotConsumed, where you can grab the successfully decompressed data