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 the index of the end of the compressed stream, relative to the last data chunk consumed.

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

print(get_end_index())

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: stream-inflate-0.0.9.tar.gz
  • Upload date:
  • Size: 5.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.9.tar.gz
Algorithm Hash digest
SHA256 11f17cf6742f1f234cac51c563cc01e617d8b09e1f57e970ffb0eab7fae58e17
MD5 f07c2d6acc672e9db567da74b9e3a1e5
BLAKE2b-256 d7ae64cd16dfb4e5e4ddcdd956a7982c33db9de848b11b55353bcfaac761f9f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stream_inflate-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 5.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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 e36124fcdc8e2049fd740f4e5bc592d48e76e3cc445f6904ef05ac788df686bb
MD5 1632dbf165d6620837612177ad6b963c
BLAKE2b-256 2298526d78aef5dc17070c04962965f5ba95d7a6849d9bb761aee8d7f86abda8

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