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.2.tar.gz
(8.9 kB
view hashes)
Built Distributions
Close
Hashes for zlib_state-0.1.2-pp37-pypy37_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f22c3a2ed84c9d3fb064a2396a8a28e42fb0c73f815119965fd7681f232c78a |
|
MD5 | 6ecffe1c896989ea507eb206114e58c9 |
|
BLAKE2b-256 | bb04d4ee0c7d89c780ef590d260c6b12b69b24651bc56e8474925aed88acd6b3 |
Close
Hashes for zlib_state-0.1.2-pp37-pypy37_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bc39cf8df8ea28df9c6ec1c9ee08b9afa7ef39c4f8be7f32eb58ef5889c4141 |
|
MD5 | 6b417a1a751b52de2fa1ee81602f236a |
|
BLAKE2b-256 | 9030c05b5fe1d0bf7d13e79ca49c8db2b455cd0bae13d68e62307ec0d74aaf4d |
Close
Hashes for zlib_state-0.1.2-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cc933b16185d6540df51e7a603e1a4d5d2a7a77973c35c146ed5b78e07d214b |
|
MD5 | 99ea95fa488cd6e2ccc47bd84c228cd8 |
|
BLAKE2b-256 | 9be28993f6f3a80bd77198573b73f2c4951f96bd161c704365921edc6ff7a4ca |
Close
Hashes for zlib_state-0.1.2-pp36-pypy36_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8e05d06f8e299d4ca9e8abcf150c1d579b085be5aa24a5e6419d6b46fd31d7b |
|
MD5 | 1d0cfa43b38f9661474ec02d9c01a730 |
|
BLAKE2b-256 | 07b9eab670e8834dc5726f8e2659ffc205f10d63bb872260b0caca8d1e6b8efe |
Close
Hashes for zlib_state-0.1.2-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47afb7efdb0349bf7ef5b4399bf0a462d1c118561409fd74b6aff5146182c3ae |
|
MD5 | 9f50bff07db7d4b7350c9b9f8b260784 |
|
BLAKE2b-256 | aaab8fc77f3637001aea46d525319816ff9105372614501f13628aa44874f09d |
Close
Hashes for zlib_state-0.1.2-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01fd388d6a4e0e61c15ed5cce79722cc745244da10fff83698ce0080fef0ca84 |
|
MD5 | 65ed073f837a9752b50eefeb35f035ea |
|
BLAKE2b-256 | 36e4bc67cd91a16e6f4cfde810b15896f98161ef05788c27950bbcb0e448f65b |
Close
Hashes for zlib_state-0.1.2-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a188721ced38968366cc2a5e850cd57bad156846cfb954a4bbfee18f608dfd99 |
|
MD5 | 33b30d05fa43a7271a3a2f6dbb9ba89f |
|
BLAKE2b-256 | 9b030af4ae1d88f4f2eddac2de7ceb44e30da49218da7adf922e3e84e7fc0937 |
Close
Hashes for zlib_state-0.1.2-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f069295f50dbd545715b8f8a450c87f4a4ab44128501ea3f104923f4fa6cd9cb |
|
MD5 | 0e94d4a542e05b58bb894e5e1779a3c5 |
|
BLAKE2b-256 | 2577b93cd8a5f7e1abfc438ff75827cb9fdd5c527c1e5116d9ae3196e877e92c |
Close
Hashes for zlib_state-0.1.2-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 354b82305d2a903191f5b80e690352fcd0a7c11513390297b7cfbc56e37fa604 |
|
MD5 | b289969dae3f1964fb651e1751ef540d |
|
BLAKE2b-256 | 40b12c319f66a622ba9cfd4f62c9906fd559a927d8aaaf5a10eeb98a97243711 |
Close
Hashes for zlib_state-0.1.2-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72d91aeb883b80a477b7e05dab68f6d4b22c264f6de5934803fd52c6bb912ed1 |
|
MD5 | 7281935c7255bc16bee2c97719e1f53a |
|
BLAKE2b-256 | 83e8dd933217fa33fd0e94f4c5f54e7a0d492c3680a74d2bf4acecb4195bf311 |
Close
Hashes for zlib_state-0.1.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f560a6c790fb753db64e4fc91a431fe1206d2cd6eb7e1efec51e4e16dc0e2ec |
|
MD5 | 936db6db3e04f9db04039a79e2001de5 |
|
BLAKE2b-256 | 1ee96041e5144162bf2e2f6a6b6404c0ab17325feb0f9ce7c0143917b5b2c349 |
Close
Hashes for zlib_state-0.1.2-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7c22aeed112e86a3e6a1a0dd48d3a172bac49ad702f633787cf038bde9b99c1 |
|
MD5 | 81265a1ad89246548186dc5ad91a0734 |
|
BLAKE2b-256 | 93ea64499c9855cd135aeb55f76def8d21f203433e3a9e6982042140eb8f8b61 |
Close
Hashes for zlib_state-0.1.2-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57855706a592d0abb858c0c7519569c9284ff54cf204a5548d2c7f99f62a0e62 |
|
MD5 | a6de7fc98a76bfbfeb86d705624245b2 |
|
BLAKE2b-256 | 162c9b68f283060cae272a8632ef39fab87089197814c906f8cf5fa7f9a4e1ed |
Close
Hashes for zlib_state-0.1.2-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6accba7775d1755e75e9c0ccfc187352f4712dd4242ab2042792c7e7602f2031 |
|
MD5 | 817a7a2a85e983c14e847bf0c05a450f |
|
BLAKE2b-256 | abec3ab754e8da48471d198274c9727c1a26141a66364ca2579e7c4c614c260b |
Close
Hashes for zlib_state-0.1.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa36052dcd51d2c1bf992b6452026211ac77be48c6210accb5c28ef099f18b9f |
|
MD5 | cc7bcaebc58ef5bcd31afad7aebed7e9 |
|
BLAKE2b-256 | ed5f8a3c33fc6cac78dd4b324d33af1078630701f6d3dfdeb96dedd94dbd5e8f |
Close
Hashes for zlib_state-0.1.2-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8ec7fa6d782f1d6fb8a11845ba7d6e58d339fa83e31bb71857185a530983f5b |
|
MD5 | e91b443287c61e596799820a220c7a01 |
|
BLAKE2b-256 | 2e47afae850edebf4efdec352eb7a092cbff752bc3ece817aa96fdd2d38264fb |
Close
Hashes for zlib_state-0.1.2-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e103f10539ddec5673594da072e35dcc5e5791d97547d8a3a8916f7e05892e1 |
|
MD5 | 8f27c7dde428209e0b879c0b55f4e904 |
|
BLAKE2b-256 | 36134e8495b8f525d6ed4030cc093f7c47488b34fd656335e8c6574e51074450 |
Close
Hashes for zlib_state-0.1.2-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23f09b08ad1eca6c7ba6dcba7d0b8770e39a55a5ff2cf1d3f83455fa79e9cbc4 |
|
MD5 | 06b0ecb04eb5947f6f1b6cb3d9e8f669 |
|
BLAKE2b-256 | b455755d588917173fdacb4bfba9af42e2fd65631a755bc33073aa65be1a9240 |
Close
Hashes for zlib_state-0.1.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5da9204041b2a4d73afd204bbdc2158cc60d436ef5e412b852b20096fb36406 |
|
MD5 | 4247fa2978a9a7c12e82a1830eaab66c |
|
BLAKE2b-256 | bf95e718cffec41797bbdecc7f4b874c33d1ab453c3ef558b5f58af20d593e53 |
Close
Hashes for zlib_state-0.1.2-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d56426fefa1ded4f5dc4d8ab95fcf8723db64f398b45b6435a470492b929b6b |
|
MD5 | 3c9d8b3535827bdd678280df73202367 |
|
BLAKE2b-256 | e0b5899f7d7fe70e51c9f0fd7ae25a2f66a585846a20c6924769ff28fd0059c9 |
Close
Hashes for zlib_state-0.1.2-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59fcf65b721c8d2196f6bcbd8c0c9e67054a9970c34149c24cc9fb3db96cd84f |
|
MD5 | 7a375ac51aaf83db63b71aae82a83df4 |
|
BLAKE2b-256 | d3a56b6a543353ecb19bc0e8cfe7edf77d6bf43adc6d03903a3cb284c4ad656e |
Close
Hashes for zlib_state-0.1.2-cp35-cp35m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73e9876714ce6d7f4118cbbe9d7859715d40fe3f5c9fd72b269b68205e1e3cbf |
|
MD5 | a93f4c3699e76de243feed11b63b171c |
|
BLAKE2b-256 | 5227e4bc9a1b099adc54e592f3b31b213300717734c909f2f63e9d037ffc8b55 |
Close
Hashes for zlib_state-0.1.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2332e38afa3bb0aa7db353143b03b2ba288c988e101e4370e2031027773c674a |
|
MD5 | ea114e8c085f471360982760ad77dd90 |
|
BLAKE2b-256 | f919952224a2222c0991b90b3a0caa39f86bbe4b3a3babdf8b2c252d3612240e |
Close
Hashes for zlib_state-0.1.2-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f56e2a5a0edc1e3d30cd849873a75407a2b70b4d8cf0391e4b9efafe49d4d60b |
|
MD5 | 30c8f2aeb8376aba4062d2dbdd20cef8 |
|
BLAKE2b-256 | 85709bb804df14defb4fa510271ceb969c745067b1fc4ac3b5eade1afc6c75a2 |