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 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
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.6.tar.gz
(4.8 kB
view hashes)
Built Distribution
Close
Hashes for stream_inflate-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11fe1346da51eec777f7433a498bd469f7ebc6f3cc259044d4d4b39ba799cbc1 |
|
MD5 | ff73f8b1fc1f92a46210d316459d14e1 |
|
BLAKE2b-256 | 66f1a1cea595f223946bfcab1cf86755bdbea5b7d9b6716728cb9ea16fd98a99 |