Stream Inflate

0.0.43 · active · verified Sun Apr 12

stream-inflate is a Python library, currently at version 0.0.43, designed to uncompress DEFLATE and DEFLATE64 streams. It is written in pure Python but is compiled with Cython for performance. The library maintains an active development status with frequent, small releases addressing new Python versions and bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `stream_inflate` to decompress a DEFLATE stream. The `stream_inflate` function takes an iterable that yields bytes of the compressed stream and returns a tuple. The first element of the tuple is an iterator yielding uncompressed byte chunks. The second element is a callable that returns the index of the end of the compressed stream, relative to the last data chunk consumed, useful for streams with trailing data.

import os
from stream_inflate import stream_inflate

def get_compressed_data_example():
    # This is a dummy example. In a real scenario, this would yield bytes
    # from a DEFLATE-compressed source (e.g., network stream, file).
    # For demonstration, we'll use a pre-compressed string.
    # 'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaIQ\x04\x00\x1a\x07\x04\x16' is DEFLATE for 'Hello, world!'
    yield b'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaIQ\x04\x00\x1a\x07\x04\x16'

# To uncompress a DEFLATE stream
uncompressed_chunks_iterator, _ = stream_inflate(get_compressed_data_example())
for chunk in uncompressed_chunks_iterator:
    print(f"Received uncompressed chunk: {chunk.decode()}")

# Example for a real network stream (requires httpx, not a direct dependency of stream-inflate)
# import httpx
# def compressed_chunks_from_url():
#     with httpx.stream('GET', 'https://www.example.com/my_deflate_file') as r:
#         yield from r.iter_raw(chunk_size=65536)
#
# For uncompressed_chunk in stream_inflate(compressed_chunks_from_url()):
#     print(uncompressed_chunk)

view raw JSON →