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:
python setup.py install
Tested on ubuntu/macos/windows with python 3.5-3.9.
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.3.tar.gz
(8.9 kB
view hashes)
Built Distributions
Close
Hashes for zlib_state-0.1.3-pp37-pypy37_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d102bdfa21d799786cc0510f20c1aa5e5aa66f4dbaf64818ec0ec67ebba82715 |
|
MD5 | 6f71e34270472897075d81c453ceb503 |
|
BLAKE2b-256 | a8077f4632c3376c70c3ac32bc6d3eefcab494e8c2324b55725d6a7cbd231f11 |
Close
Hashes for zlib_state-0.1.3-pp37-pypy37_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c39a4aa169ce9463ce25bd20ea9cf040acc837a99017aaec15587cf594063280 |
|
MD5 | 9922d7313ad9dea70d96857d77562b2f |
|
BLAKE2b-256 | 70da5dd9de1b45371f7a243c009d39072c445e3566b9aa730052403815e4fb3c |
Close
Hashes for zlib_state-0.1.3-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7851b2fa407e5a8cfe91dab4204ee1c272ab961b593653f881e87d5df0c2b6db |
|
MD5 | dfc832762ebe4e7e9d4c082af8d696e6 |
|
BLAKE2b-256 | a521d310b1b14cb7439e75803c020a41a358573204322fe995c3bd2b16964619 |
Close
Hashes for zlib_state-0.1.3-pp36-pypy36_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 352ff7ae055551c83930cb7d8bb2490072b167e30afb6a72d1b6c7680315a285 |
|
MD5 | fc9fe05e58e6c3cfb7de81a69d1634ed |
|
BLAKE2b-256 | 3d98af2e391845ef1a3b985880cfe56d7230ba5e579b46eae7ff0e9fc03dd4bf |
Close
Hashes for zlib_state-0.1.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27f22a1eb84848b26fef0ad6b47c240d77c8c81e21599a9eebac1838b8b06a97 |
|
MD5 | 0fba6e1f411b7b46b52a086e3910336b |
|
BLAKE2b-256 | b45d5bf504f41256b40f745cc62c1c88ef68e54c4929c2bf9cb7ee2d4ead6739 |
Close
Hashes for zlib_state-0.1.3-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87f1ce811c0bcccfd892dcd85b5fb252f5bbd9f55c6040a7ab4211797ade4a83 |
|
MD5 | d49404c46440c22af920893260ee5427 |
|
BLAKE2b-256 | c7a13cf6d3eee7e686c306c6078b58bedda4ce5066b955f1d7909ed3a7fb2f24 |
Close
Hashes for zlib_state-0.1.3-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d88ad0c6a38d4816302e3ad218e5abbfa265bfb0a29a744883a13e30610a246 |
|
MD5 | 27ab3b0781f1c5020d5331a8c760e971 |
|
BLAKE2b-256 | c19716908e6e1d4ded3a24a616b64bcc9f45b845ab26aa67fd9031fde251ff25 |
Close
Hashes for zlib_state-0.1.3-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe462a8c0301dbecb785454a7f07d50b38dab161d106c7a69466168eba7e8415 |
|
MD5 | 6894896a7aab2edbaa09f70e70c636ea |
|
BLAKE2b-256 | 62774be3e0f64a9532611a4b9d5a8fa33195c9c4301c0350195d842cefb367b8 |
Close
Hashes for zlib_state-0.1.3-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 670a1659e423f93569a0ebf45b0320a0c42c291b51e0669a40e5941d2e678636 |
|
MD5 | 0a951be2fbd875b334f0c53eeba6cb26 |
|
BLAKE2b-256 | 124aef413cdc01b226b62ed7f8a6a0ab4e00c7d18953f5ced591f02b42baf91f |
Close
Hashes for zlib_state-0.1.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7ece5414efaf15ece582066789e45f072810fc53c98260c9991ea68d342f875 |
|
MD5 | 7fa8d8911e933c2dea42153565a596a7 |
|
BLAKE2b-256 | 0da9bad440b63012c97985086e8fbf0c97751c4efc075aa357b6250d5d10f7bb |
Close
Hashes for zlib_state-0.1.3-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcb5ddd39b5b603fc43880043068e443f2932145e30e217341bd1013d4ac05b4 |
|
MD5 | 665ad28d9466ed7c9fd0b0387f40cb84 |
|
BLAKE2b-256 | 56ed8d28d1e71f9554f7a5a7668ecd6aba9fc3daef645e716c19129f8aded006 |
Close
Hashes for zlib_state-0.1.3-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e424b9e059738b4ee6d1c7729da1812c213d56a45be050c8cdaa007ea96c79e0 |
|
MD5 | 298b67f2e209c45171d9f66557679861 |
|
BLAKE2b-256 | 64dbe2712530e6962f7adee1b71b7841f2d588b25a975eb289552cf7d24c1ed5 |
Close
Hashes for zlib_state-0.1.3-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 615f555c67c86a6e0509070d433d76c88d40f13d5f521bf241390c618ba22094 |
|
MD5 | 71646f6d76dac69ab04d8ced0b0675e6 |
|
BLAKE2b-256 | cc8f6e4635b75019b3e635016a1d2198b552ca0308d8fc250b34c4db861f0d24 |
Close
Hashes for zlib_state-0.1.3-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa82091fd6b3454ea2d63727d43af8dbf39db836ae7967bfb96b628953ce1408 |
|
MD5 | d4907099c3e6117bdefb996256b2a05c |
|
BLAKE2b-256 | 1b1e915ae1ab907c90a7bba9637c07dce4f887f1f1fd98da87de217622def5d5 |
Close
Hashes for zlib_state-0.1.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04ca003402146a57d2b36c486f548f4bf6508155974363dceb0802cb05a4d1c6 |
|
MD5 | cf75e84c20a0d7cada6b85101a046c90 |
|
BLAKE2b-256 | f108e44bee896e8f0936c84d062a1df8d22071795edb321c318fd88da1ce68f7 |
Close
Hashes for zlib_state-0.1.3-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd18eb3c2d9c48c59d0bbcb3765d67ed035c439f72653533e1a791fc834d956a |
|
MD5 | 90a82d6efba6fb14a75e939d648d96bd |
|
BLAKE2b-256 | 690595df36be761a5ff85a39b438d87937f02762c19fea95c0f10b679a259f14 |
Close
Hashes for zlib_state-0.1.3-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a8d7a2541164a5a477aef4c170ac4997fb90e8676b0076da7d9288db0937a51 |
|
MD5 | cfe4dcd03b64ff547e0ed79555941578 |
|
BLAKE2b-256 | 71b520f7d7ca11ada4b5a37b10894a5d11e47cd9816e69d897debc8cb922142a |
Close
Hashes for zlib_state-0.1.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81c2390d7791d192024543fd4d5e5922ca26904a9551de7c1dd6394429c685dc |
|
MD5 | f075be2cd8407a990f7b6c6849bb0479 |
|
BLAKE2b-256 | aa0fd72aa75947a7cad80d8afd6264cf93422ef003331ad6238ddd91c78ce2e8 |
Close
Hashes for zlib_state-0.1.3-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db525aaf9eebe5f11c2f8b2defa131f099d54592eb305fe84c7472424dd2fdaa |
|
MD5 | 7830e6be66b1a553a4cea35884c970c7 |
|
BLAKE2b-256 | 0e032a3821203e85e2b40429b8ca42930a0ec7dc760f4ab204ab06c41025e596 |
Close
Hashes for zlib_state-0.1.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93455149db5e9ba3e4888d59089ba21d64ddafadcfc8e6d14c5845d5c844835f |
|
MD5 | 4426d4a6661b487dfa99f63cfd9848e3 |
|
BLAKE2b-256 | f7aa508fdfb52c06ab47938c88c7dbdc877196f20fb646a60c82b8ccd88f4d3a |
Close
Hashes for zlib_state-0.1.3-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b6425ab0597e2f62290da30aab20f37f4c3bbad113b5e7b40d9e598e4a2a9bf |
|
MD5 | b4109fc594b208abfbc8521d51402278 |
|
BLAKE2b-256 | 28e701896ab37bc5cd28879ff1c3538491940943c92e61686a98561cd64ddef6 |
Close
Hashes for zlib_state-0.1.3-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42c0916c1638fe4b1ff752b470ce0af454cf4c2e30bc56accce3f6ff1eb904ab |
|
MD5 | 06720f79f61325c066fabd0aa1f5b4f9 |
|
BLAKE2b-256 | 5e0418915250dd3996e8f4a710991ce0d9742d53c901949b9432b1c0ca2e5dbf |
Close
Hashes for zlib_state-0.1.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b18e32c1d102cc05c7cfd2853b20d5f1057d7afa1268da629bb1e08a46b6356 |
|
MD5 | 343a910a53c6c305deea986213750641 |
|
BLAKE2b-256 | 4a9a940cacbe0a1c22c4d3e3cb125625b038872bea5872d5fbefd529df0a7bad |
Close
Hashes for zlib_state-0.1.3-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6817a1b1185eefc47cf2216a5c9c33427715784b9be8728dbbea484055da44a9 |
|
MD5 | de1a12b82580243a32dcf1575b5a95e1 |
|
BLAKE2b-256 | f43355778be842ff5f9a280aa57e5dae107e97b90443ed724fa53fc0939e992f |
Close
Hashes for zlib_state-0.1.3-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b90458d6f3e099b1219c28a0cd65e992336a908a17569f3509835e915883085 |
|
MD5 | f656a383a0d00407a6fbcf99fb68c3b5 |
|
BLAKE2b-256 | c05c690df941564d252a9b59b7835a1f7bf1cda9f919b6709a222515d8caea3e |
Close
Hashes for zlib_state-0.1.3-cp35-cp35m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b2a3fc9817722c1e958686320b23389ac2930c50eb6e592127bc7738f69c36d |
|
MD5 | 33f8a934df0c9a7238916ebb9d4527ac |
|
BLAKE2b-256 | 46fc573f8bdfc25979d393a8f4aec6cd1d13bc7d5e6e7fb03825f7bb3c168187 |
Close
Hashes for zlib_state-0.1.3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba8a392fb7a808f7bff7c93d2437200ef1a7b371dbf17136bd6047016d34c857 |
|
MD5 | fa36ccccf357737eb5243e10b987355f |
|
BLAKE2b-256 | 98afd26e04b29efd62a8f77bc0000d505671e264e473cd3e46e92eab1131bf03 |
Close
Hashes for zlib_state-0.1.3-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cb1f9814baf6fcdef3f7ac8c4df2c1680ab9b0cc6e702d855391cd391224ebe |
|
MD5 | 233a9e2e8850da1710eb512513492acf |
|
BLAKE2b-256 | 6c1804345a2b110a7f8b84bee4c7599435f041f6b3502c8c7fe126b49572cb69 |