inflate64 compression/decompression

1.0.4 · active · verified Thu Apr 09

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

Install

Imports

Quickstart

Demonstrates basic compression and decompression of a byte string using `inflate64.deflate` and `inflate64.inflate`. The `max_buffer_size` parameter in `inflate` is highlighted as a critical consideration for robust decompression.

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!")

view raw JSON →