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)

If you have a stream that has other data after the compressed part, but exactly where isn't known in advance, the following pattern can be used to retrieve it.

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

print(get_unconsumed())

This is possible since Deflate and Deflate64-encoded streams indicate their end.

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.7.tar.gz (4.7 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.7-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file stream-inflate-0.0.7.tar.gz.

File metadata

  • Download URL: stream-inflate-0.0.7.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6

File hashes

Hashes for stream-inflate-0.0.7.tar.gz
Algorithm Hash digest
SHA256 8355fbd9b1251e615bb813db2b9c36558c9b9769c92c5bc86e975083498ebd20
MD5 8695e7593e5365c76caf7843ed07f291
BLAKE2b-256 489386e68e48f5e38222ac65b48044d3a43e0171cc19d05e219f59de56e14ab3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stream_inflate-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6

File hashes

Hashes for stream_inflate-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c97dbd8da52968c73357d2333b29d53fea4556409ae873d1c7ccbb380fac0b19
MD5 05492ffb7ed1ed718dbc79c859e8e50d
BLAKE2b-256 d212b2fbe41fdd68e1933104ab754c6b8361338cee92450c2c77bf52ecffeeaa

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