Low-level interface to the zlib library that enables capturing the decoding state
Project description
zlib-state
Low-level interface to the zlib library that enables capturing the decoding state.
Install
From PyPi:
pip install zlib-state
From source:
pip install .
Tested on Ubuntu/macOs/Windows with Python 3.7-3.12.
GzipStateFile
Wraps Decompressor as a buffered reader.
Based on my benchmarking, this is somewhat slower than python's gzip.
A typical usage pattern looks like:
import zlib_state
TARGET_LINE = 5000 # pick back up after around the 5,000th line
# Specify keep_last_state=True to tell object to grab and keep the state and pos after each block
with zlib_state.GzipStateFile('testdata/frankenstein.txt.gz', keep_last_state=True) as f:
for i, line in enumerate(f):
if i == TARGET_LINE:
state, pos = f.last_state, f.last_state_pos
with zlib_state.GzipStateFile('testdata/frankenstein.txt.gz') as f:
f.zseek(pos, state)
remainder = f.read()
Decompressor
Very basic decompression object that's picky and unforgiving.
Based on my benchmarking, this can iterate over gzip files faster than python's gzip.
A typical usage pattern looks like:
import zlib_state
decomp = zlib_state.Decompressor(32 + 15) # from zlib; 32 indicates gzip header, 15 window size
block_count = 0
with open('testdata/frankenstein.txt.gz', 'rb') as f:
while not decomp.eof():
needed_input = decomp.needs_input()
if needed_input > 0:
# decomp needs more input, and it tells you how much.
decomp.feed_input(f.read(needed_input))
# next_chunk may be empty (e.g., if finished with gzip headers) or may contain data.
# It sends as much as it has left in its output buffer, or asks zlib to continue.
next_chunk = decomp.read() # you can also pass a maximum size to take and/or a buffer to write to
if decomp.block_boundary():
block_count += 1
# When it reaches the end of a deflate block, it always stops. At these times, you can grab the state
# if you wish.
if block_count == 4: # resume after the 4th block
state = decomp.get_state() # includes zdict, bits, byte -- everything it needs to resume from pos
pos = decomp.total_in() # the current position in the binary file to resume from
print(f'{block_count} blocks processed')
# resume from somewhere in the file. Only possible spots are the block boundaries, given the state
f.seek(pos)
decomp = zlib_state.Decompressor(-15) # from zlib; 15 window size, negative means no headers
decomp.set_state(*state)
while not decomp.eof():
needed_input = decomp.needs_input()
if needed_input > 0:
# decomp needs more input, and it tells you how much.
decomp.feed_input(f.read(needed_input))
next_chunk = decomp.read()
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
zlib-state-0.1.6.tar.gz
(9.5 kB
view hashes)
Built Distributions
Close
Hashes for zlib_state-0.1.6-pp37-pypy37_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e94fcc6158d72ee4b517190d84074f134a1752ab1dcb398946f98e64fe29bf2e |
|
MD5 | 1c67a1b018f7933bb6b6c1ad14b6adbc |
|
BLAKE2b-256 | 07067392ad49923d6bd88b6f2dc49dfdeb0ada2a188e4b6048af451b3a4c6c53 |
Close
Hashes for zlib_state-0.1.6-pp37-pypy37_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f3dae845f2727529786b6f8b12ddbbcbf8611fcf8e34d3ce1cb6ba50b77ec88 |
|
MD5 | 8877b890353de54621bdf8fcd43d3709 |
|
BLAKE2b-256 | 6efaca91d20055605cfad7d3de52c9e848d4fa9045eff9fa86e3fa44b1fdf034 |
Close
Hashes for zlib_state-0.1.6-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1697685eabbc5d165a4386033cc099451618fde0718e51b819bfb22833a0e21b |
|
MD5 | 9ff3eb4807e92dd37a36ba36c9cdf276 |
|
BLAKE2b-256 | 5a85c35584cd3276f02dcd81b6e6598f291708b29d0166bcb4d6cebf734cdc64 |
Close
Hashes for zlib_state-0.1.6-pp36-pypy36_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4b46cf29d98cdb732a7acefdb5e93fcaea7ca511146ad59101d53923c6626af |
|
MD5 | a8dca7d1f8b7a429762fc4f96ecd29e8 |
|
BLAKE2b-256 | 8ac7748131ab06bf23a4ee1d475da5a2834ed3328bab6e1f61dad8000c9ef96b |
Close
Hashes for zlib_state-0.1.6-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a412e89b48c7506552ff87368689608aab37df4a33570cbcc4c0699c2492fae1 |
|
MD5 | 611f03886d2bbb4411c803868e05cce7 |
|
BLAKE2b-256 | e64931993376b86675c485e24dd23e5e599c1179d59aa3acee04cfb4650bfb40 |
Close
Hashes for zlib_state-0.1.6-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3646062ab49c3d1d3e100149a0f4a261972eed5424766b11a8e49c71422398d1 |
|
MD5 | 0164ac1ce17b7e2517d62a62ff6116d7 |
|
BLAKE2b-256 | ed6ed232740b6ee40832ebf9e0d4f83f8a82f8a3339f1a1476636cc032d55d44 |
Close
Hashes for zlib_state-0.1.6-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 463c0e1b688c5e0f568d89b92799ccf14440839cc54212adbc43ed4f7a0e129d |
|
MD5 | d91134b94902878410ff0481d16a6853 |
|
BLAKE2b-256 | cd25d694587b1e6815d9642e17409b9d8374b612f685e610aeecadfb2dc74b7e |
Close
Hashes for zlib_state-0.1.6-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fafbb5b06db615b48e27ad47cea6d6d2eb04250e7642d692983ead433454ce51 |
|
MD5 | a5a3a3590b4a3f8e64ad7dae5f0078b8 |
|
BLAKE2b-256 | d31d2eee145b187a7470bbd8b649dedb5a9f2c641adb3650433c7741cfd7777d |
Close
Hashes for zlib_state-0.1.6-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7261c02284fc81f39373ba0be7f55b44fbddc7b46eb588c8620a74b6059b1a4c |
|
MD5 | 1b2d7b6157d041f4b13ce9bcd23e9744 |
|
BLAKE2b-256 | 45cda9b33c35c38842ffa1b1efe298558367cff56fdfda0c8a802ea7113ee4cb |
Close
Hashes for zlib_state-0.1.6-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8bd45d38d853feb43109f075dd5900c4395a82a400c383a38faacf1cf681bb9 |
|
MD5 | dca3fe5f66c1c20a372e525d12319efc |
|
BLAKE2b-256 | dae8e5bae34ed5d7068a7424318932cef8a600d1244a81de9da3cd0c85334a65 |
Close
Hashes for zlib_state-0.1.6-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b09ef667a6049346ab98bcd74a118885b2acafcf59ffeb3b3b51a9ead7d24b3 |
|
MD5 | 5aa9abcb98fe1a42048ab6fc384b95eb |
|
BLAKE2b-256 | 8d60f2e138caf5b7e6cc150ce33a06856f98baf7f87485cc81216589198db6a6 |
Close
Hashes for zlib_state-0.1.6-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38451077ef3732920d89b2194ad01c4a6523d7f3f1aff50d62da050bfd6d2a0d |
|
MD5 | c9c0d1aab143134d5952560c16790231 |
|
BLAKE2b-256 | 577b80d8bd86d1f3378c0129bdd2a4c466b5d545d3f7d187b8f83fa8e7b1a79d |
Close
Hashes for zlib_state-0.1.6-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc1723b1d41a026374cbb8154fa916dd987002a0bcc450fd9f77bc2d28761f4a |
|
MD5 | 213a41fcb1c6d70630f7830eca7a84fb |
|
BLAKE2b-256 | 66c66e082cc29097e071735daa0497ed06d27fee8ba0289395f1ef057a220834 |
Close
Hashes for zlib_state-0.1.6-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a49525c711e42b5bb53b723f0bd0e3b1db8eda40f89be7e21497cc31856e2e4 |
|
MD5 | 0560965ccb04a34be849c7563b04ed9c |
|
BLAKE2b-256 | 962da219a4c0a9dc23a0d65965747bae29c36d6f926baa9c54b77c7a24772bee |
Close
Hashes for zlib_state-0.1.6-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87a2816f8c8fb26d3312a6460294f9cae87056f6a1d4cca503234d586aa3c077 |
|
MD5 | c0c4ee3ab4dccc16802390102f6c9069 |
|
BLAKE2b-256 | 2cdcc1fa11b8d127a0426659c967eaf0e1eaab1e1d90451a5c06a3a8265fdc33 |
Close
Hashes for zlib_state-0.1.6-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b10eb76845cb5b8e13a92139d829fb7df1f512e2c646041c6caefd5efcf2812 |
|
MD5 | 7ac59f03f1bceaf80dc592e371112ebc |
|
BLAKE2b-256 | 14414786b853d03a7f168f81b84d3b1632a11fd96cdf7b908d9138fe95a5fc83 |
Close
Hashes for zlib_state-0.1.6-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b2dac3abc54a0ac8a9b8d07443608e1fcf91eca977e2ddb92641df1718d6201 |
|
MD5 | 1393e2a5801f0f4d2d895a6528bd8e2a |
|
BLAKE2b-256 | 927f2d1ec05ee544f47e2474b124d4b02cbb1c3b94db9d34871c543c43795fa5 |
Close
Hashes for zlib_state-0.1.6-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad4bda26ee8100b2c616e5312f432c8e3fae6e3f66a0b1ab6d40fb1d7fe5404b |
|
MD5 | 93c99c7caf1380c0f4f3fa6b77a5de1c |
|
BLAKE2b-256 | 5453e654f4e65cd8639abbf3845f148fdbdc0a0f65ec7f238f808f6f88b9b08f |
Close
Hashes for zlib_state-0.1.6-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd63c7269bbfd44993dcb3b1fef6799f13b7a5b91b53c1d0c46a0ec85a100bf4 |
|
MD5 | e44f66ef58b43645db4f6092f4f0814e |
|
BLAKE2b-256 | dd602863ef9e01a9ccf689efeeebce27d3ed26b3ef1a1938f0f7939a05d9d505 |
Close
Hashes for zlib_state-0.1.6-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0daab8b7836c7d1fd695e1041207869b30207e55dff8168eadfc1a1c1227ff77 |
|
MD5 | a3143f8d75455fcf52c41d733f5e01d8 |
|
BLAKE2b-256 | f6a3e65e830fa8aca220b2a6ec12b25e03f849f05c87eb695ac4ddd37560480e |
Close
Hashes for zlib_state-0.1.6-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ce67536d4aee48e0b3e7d21d7cece704196615c2cd2d74c34933c35c116ef07 |
|
MD5 | 8899651f21a41029b0aa029b7ccc010c |
|
BLAKE2b-256 | 9def23029e3bf08079681b216fadf0812de74c45cacafbb7327a806636411bf0 |
Close
Hashes for zlib_state-0.1.6-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fa2d6334e98057d0b54decbab75638ff148f0fc27d7461f8bd660b8397d2a2c |
|
MD5 | 16de703e8b4066bc4139b98381455677 |
|
BLAKE2b-256 | 6196db55653dc79e8e14091b37f6f89d105099fc0cfadf596c7f06690048a411 |
Close
Hashes for zlib_state-0.1.6-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a3d7476fd9ecae274bfd13bc5b85488f1265452b1821c8bf4410f8536bcb0e6 |
|
MD5 | 4dee74d61a8f60dea00a99b37e15d7ef |
|
BLAKE2b-256 | cc08fb6994b54d180f6a7388d29682879c88f93d9dc832da9dd1e52d9c9ba9ef |
Close
Hashes for zlib_state-0.1.6-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19dc4dc82ceaa34a45a1cd0e23aaaf2848d5a817120b0ba320bc9337c2e041c6 |
|
MD5 | fde4b9013bd955dbc8840d624d74752c |
|
BLAKE2b-256 | 63067dbe98d7f2f1e7c9dd9eecc3ef7096801c2027623ef5dfc82e4725b5b3a5 |
Close
Hashes for zlib_state-0.1.6-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74cce17a782a56645a4266d703d4fe8a6c54fde202923eba4bf1a86ef406ad57 |
|
MD5 | cf0985b9ee2bbf6ba8cb0056b3084a9c |
|
BLAKE2b-256 | 42c5816538e02d99d30863748521cd5c14c3d789bac5dd0d091c9860eddafb40 |
Close
Hashes for zlib_state-0.1.6-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6203314f1feb9224114a59914f68a9a540d12b9f79ca864a70c03b89eb0686f5 |
|
MD5 | 8de6af4992a36d86742b2aad8237ac63 |
|
BLAKE2b-256 | 73b26d3bdbe1e9e1b65fc30ed4b0e455e652b670ec4529d28961a14204432807 |