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)
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
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.9.tar.gz
(5.0 kB
view hashes)
Built Distribution
Close
Hashes for stream_inflate-0.0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e36124fcdc8e2049fd740f4e5bc592d48e76e3cc445f6904ef05ac788df686bb |
|
MD5 | 1632dbf165d6620837612177ad6b963c |
|
BLAKE2b-256 | 2298526d78aef5dc17070c04962965f5ba95d7a6849d9bb761aee8d7f86abda8 |