Skip to main content

Uncompress DEFLATE streams in pure Python

Project description

stream-inflate PyPI package Test suite Code 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()[0](compressed_chunks()):
    print(uncompressed_chunk)

To uncompress Deflate64, use the stream_inflate64 function.

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

For Deflate streams of unknown length where there may be other data after the compressed part, the following pattern can be used to find how many bytes are not part of the compressed stream.

uncompressed_chunks, is_done, num_bytes_unconsumed = stream_inflate()
it = iter(compressed_chunks())

while not is_done():
    chunk = next(it)
    for uncompressed in uncompressed_chunks((chunk,))
        print(uncompressed)

print(num_bytes_unconsumed())

This can be useful in certain 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.15.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stream_inflate-0.0.15-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file stream_inflate-0.0.15.tar.gz.

File metadata

  • Download URL: stream_inflate-0.0.15.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for stream_inflate-0.0.15.tar.gz
Algorithm Hash digest
SHA256 64249b853624fe10d32b51ac1fde73775b876f15a78794af89b7646e049477b7
MD5 60662a463bb1d0e3b3f1b9960a41b4fa
BLAKE2b-256 31a283168838843f72569e48da3308416112e4a023aa3b0ea621215265b071e2

See more details on using hashes here.

File details

Details for the file stream_inflate-0.0.15-py3-none-any.whl.

File metadata

File hashes

Hashes for stream_inflate-0.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 562a9267324cc89b88b82d3998cb8002297d8ae0bd5c65d460f4230efa67d2ca
MD5 761121587a1d62093f26b20f464d2bc2
BLAKE2b-256 cff6080900fa31cd00b839a702cd020ace7afe6ef013f43ebd9ab95094545f6f

See more details on using hashes here.

Supported by

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