A Python translation of the high-performance Zstandard (de)compression library fzstd.
This is a pure Python implementation of Zstandard decompression that aims to be compatible with the original TypeScript version.
LLM-driven translation from TypeScript.
pip install fzstdOr for development:
pip install -e .import fzstd
# Decompress data
compressed_data = b'\x28\xb5\x2f\xfd...' # zstandard compressed bytes
decompressed = fzstd.decompress(bytes(compressed_data))
text = decompressed.decode('utf-8')
print(text)For decompressing large files or data streams, use the Decompress class:
import fzstd
def handle_chunk(chunk: bytes, final: bool) -> None:
print(f"Decompressed {len(chunk)} bytes")
if final:
print("Decompression complete")
# Create a decompressor with a handler
decompressor = fzstd.Decompress(handle_chunk)
# Push compressed data chunks
decompressor.push(chunk1)
decompressor.push(chunk2)
decompressor.push(final_chunk, final=True)- Maximum backreference distance: 2^25 bytes (same as TypeScript version)
- Not compatible with "ultra" compression levels (20+) for files > 32MB decompressed
- And more!
Run the test suite:
python tests.pyThis is a translation of the fzstd TypeScript library by Arjun Barrett (@101arrowz).
Original repository: https://github.com/101arrowz/fzstd