Uncompress DEFLATE streams in pure Python
Project description
stream-inflate
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
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for stream_inflate-0.0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73fd5530a4454b5afed331b3f6607f2c439f5d0ca00f409530c4d0c2808d707e |
|
MD5 | f28d3ba5a90b3918956e975815522636 |
|
BLAKE2b-256 | 4ca9d2fa5b553ccd633644e00dc87af9ed750a4e95a1e95a55b48a41515ca25e |