inflate64 compression/decompression
A Python library providing deflate64 compression and decompression functionality. It leverages the zlib-ng library for efficient performance and natively supports the larger dictionary sizes (up to 64KB) characteristic of deflate64, which can be beneficial for highly repetitive large files. The current version is 1.0.4. Releases are infrequent, typically for minor fixes or updates.
Warnings
- gotcha The `inflate64.inflate` function requires a `max_buffer_size` argument. If the actual decompressed data size exceeds this value, an `inflate64.error` will be raised. A value of 0 attempts to auto-size but may not be suitable for all scenarios, especially with potentially malicious or malformed compressed data.
- gotcha While `inflate64` implements the deflate64 standard (with larger dictionary sizes), the `wbits` parameter for both `deflate` and `inflate` functions behaves similarly to standard `zlib`. This parameter primarily controls the presence and type of header/footer (raw deflate, zlib, or gzip), rather than directly configuring the deflate64 window size.
- gotcha This library is a C extension and may require C build tools (like `gcc` on Linux/macOS or MSVC on Windows) for installation if a pre-built wheel is not available for your specific Python version and operating system. This is a common requirement for Python packages wrapping native libraries.
Install
-
pip install inflate64
Imports
- inflate
import inflate64; inflate64.inflate
- deflate
import inflate64; inflate64.deflate
Quickstart
import inflate64
original_data = b"This is some data to be compressed using deflate64. It's important to remember that deflate64 allows for larger dictionary sizes, which can be beneficial for highly repetitive large files. " * 100
# Compress data using deflate64
compressed_data = inflate64.deflate(original_data, level=9)
print(f"Original size: {len(original_data)} bytes")
print(f"Compressed size: {len(compressed_data)} bytes")
# Decompress data using inflate64
# The max_buffer_size is crucial for inflate to prevent errors on large inputs.
# Setting it to 0 attempts auto-sizing, but providing a safe upper bound is often better.
# Here we give some headroom (e.g., original size * 2).
decompressed_data = inflate64.inflate(compressed_data, max_buffer_size=len(original_data) * 2)
assert original_data == decompressed_data
print("Decompression successful!")