Skip to content

dholth/fzstdpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fzstd - Python Edition

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.

Installation

pip install fzstd

Or for development:

pip install -e .

Usage

Basic Decompression

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)

Streaming Decompression

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)

Limitations

  • Maximum backreference distance: 2^25 bytes (same as TypeScript version)
  • Not compatible with "ultra" compression levels (20+) for files > 32MB decompressed
  • And more!

Testing

Run the test suite:

python tests.py

Origin

This is a translation of the fzstd TypeScript library by Arjun Barrett (@101arrowz).

Original repository: https://github.com/101arrowz/fzstd

About

Zstandard decompression in pure Python

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages