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()[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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
516cdae24e3f4eeb09736401fbd30c203e4042547a2e038285c91ed1f6126a72
|
|
| MD5 |
28aa5af7ccc6d8cf40a0a42bed838a37
|
|
| BLAKE2b-256 |
d822748a59bc05a24b2e737e26d0f4764833421ea24b173c678247a0691b6245
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dbec37e8a434564f54aa53e49de83cab56f3209ec92231446cbff0cd4925016
|
|
| MD5 |
8687dcf1de030681006ef73543fab35b
|
|
| BLAKE2b-256 |
c844d80cbab6d9365f5066189781b2be240f0c68834307b8f0432394e718fa4b
|