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()[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.12.tar.gz (6.0 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.12-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stream-inflate-0.0.12.tar.gz
  • Upload date:
  • Size: 6.0 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.12.tar.gz
Algorithm Hash digest
SHA256 516cdae24e3f4eeb09736401fbd30c203e4042547a2e038285c91ed1f6126a72
MD5 28aa5af7ccc6d8cf40a0a42bed838a37
BLAKE2b-256 d822748a59bc05a24b2e737e26d0f4764833421ea24b173c678247a0691b6245

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stream_inflate-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 6.4 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.12-py3-none-any.whl
Algorithm Hash digest
SHA256 5dbec37e8a434564f54aa53e49de83cab56f3209ec92231446cbff0cd4925016
MD5 8687dcf1de030681006ef73543fab35b
BLAKE2b-256 c844d80cbab6d9365f5066189781b2be240f0c68834307b8f0432394e718fa4b

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