Skip to main content

Uncompress DEFLATE streams in pure Python

Project description

stream-inflate CircleCI Test Coverage

Uncompress Deflate and Deflate64 streams in pure Python.

Installation

pip install stream-inflate

Usage

To uncompress Deflate, use the stream_inflate function.

from stream_inflate import stream_inflate
import httpx

def compressed_chunks():
    # Iterable that yields the bytes of a DEFLATE-compressed stream
    with httpx.stream('GET', 'https://www.example.com/my.txt') as r:
        yield from r.iter_raw(chunk_size=65536)

for uncompressed_chunk in stream_inflate(compressed_chunks())[0]:
    print(uncompressed_chunk)

To uncompress Deflate64, use the stream_inflate64 function.

for uncompressed_chunk in stream_inflate64(compressed_chunks())[0]:
    print(uncompressed_chunk)

The following pattern can be used to find how many bytes of the last data chunk have not been consumed by the decompression.

uncompressed_chunks, num_bytes_unconsumed = stream_inflate(compressed_chunks())
for uncompressed_chunk in uncompressed_chunks:
    print(uncompressed_chunk)

print(num_bytes_unconsumed())

This useful when there may be other data after the compressed part, such as in ZIP files.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stream-inflate-0.0.10.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

stream_inflate-0.0.10-py3-none-any.whl (5.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page