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.0.tar.gz
(8.9 kB
view hashes)
Built Distributions
Close
Hashes for zlib_state-0.1.0-pp37-pypy37_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8c194740437da2be806e47d758ea1d24b2ff695af7ca2441627a958ee3615c4 |
|
MD5 | 416a85ed08bc85194d23f2ba4d4cf93b |
|
BLAKE2b-256 | a3ec2e2f03a0f3627aa769fb2521520aa6e3992aba1e2479ee4fe73e69eecc43 |
Close
Hashes for zlib_state-0.1.0-pp37-pypy37_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db82fdbaa6cb251dcae1bdb53ffb07ba4d038cf50146fe801c1fd96247505936 |
|
MD5 | f1633a65221cfe9902fbf7ce9379709e |
|
BLAKE2b-256 | facd373cd0acca68b25ca61c9289521ee31d0eea3a82b333d54aef8abda8ab6a |
Close
Hashes for zlib_state-0.1.0-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 538c9a36318bfd8611193e8b40a1e29fe6e6090ce6bf95c4513cbf87065a09fd |
|
MD5 | bc59b1bcf686ce0d1fcb11be75f5397b |
|
BLAKE2b-256 | a4f16e6ac079c8b4d9bbb7cdbf60c2c5cf60646ec15f359d80db3039b0e6d131 |
Close
Hashes for zlib_state-0.1.0-pp36-pypy36_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5be3c4efdf7d5da0b1de961956c902c5f88f1c93562bcb20b9f8432564e1ad04 |
|
MD5 | 0017f078b295e4920744d53eff13c761 |
|
BLAKE2b-256 | d220d23592e8e241f61a5ab99760f5fe01476ef86a1454423561d183836bbc23 |
Close
Hashes for zlib_state-0.1.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea7a45ba3d8abd10efc382e704575fdc08aecd3920e333561aad0486f1517c36 |
|
MD5 | 6d73b5f9fc862121ce3efe50348235f9 |
|
BLAKE2b-256 | 59c75feb2d57a2d144939c25d2077896afa561daa58201309ac178906cf86399 |
Close
Hashes for zlib_state-0.1.0-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a41bcfbfd2149bac74bd03264b592a7a3aa054669171d49b4e94ff10d5302743 |
|
MD5 | 9dafc29051ddbdb688dcba0b2318e596 |
|
BLAKE2b-256 | 38e251eeb838b53e63fcd095a68bf9b3e787585b9de3896ccaefd3df7d794faa |
Close
Hashes for zlib_state-0.1.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67a79a15fa89b8ad7aa2fbcbad1253ed247f1cfdac54fbbfab4d7bc5021c48fe |
|
MD5 | 354bae367264af08677aff4173d36015 |
|
BLAKE2b-256 | 7846259a74fcb9ce28d209ee5cb9740705acdc06260ad1a753b5479bc3cc5e46 |
Close
Hashes for zlib_state-0.1.0-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b88d3cd723c20657e506a0ccab8fc20b7e309231349efe5b64c3a6bb1c400b5c |
|
MD5 | 11238d9e81e276bfe4fce24abb1ce083 |
|
BLAKE2b-256 | 7dc5fa067f67036a7fe48970e1706821edbd579e2a4cf5ae4e67ed104b370fa8 |
Close
Hashes for zlib_state-0.1.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55a19e57d8d83fc9125ecd41be120bcf45fa415e7710409adce60d63f1d6deb8 |
|
MD5 | e23b1c064788c54740281e7a4f344cc3 |
|
BLAKE2b-256 | 8e596c8403daffd39f746d43f1e321c69d352c828527176089e42e410ffb18d7 |
Close
Hashes for zlib_state-0.1.0-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c193553bd723d61a81bc524cf3f74715cd1cdb79f3fe3c87a894f7b8fc5c5752 |
|
MD5 | 107b03fcb88cc2d1a10c7c49db5a7c76 |
|
BLAKE2b-256 | c6fb5808f93ae4ee2220e746c6627a63574ee45da7c34bac0055905ac6f3ec28 |
Close
Hashes for zlib_state-0.1.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d81f929a94e4467c04aa47fe3bb4f5b3d1a99bfb0be2c0cf9119c57f5c4983cf |
|
MD5 | fb852f16257b9ebfaddfffbe9a14db8b |
|
BLAKE2b-256 | 22e6ab775928c816cb159d1fc52b3ab0a6fdda96f317903aef6b3bfd98c65ead |
Close
Hashes for zlib_state-0.1.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0930b29399bc66ffb76ac2e651930d3bfa05af92525d7085171713c080d419b |
|
MD5 | 98dc651ab008cc35c516118b743c45d0 |
|
BLAKE2b-256 | 218cc76729d8f12620d4af546321e5a17432075fff7c61a349f321ef3e57fde6 |
Close
Hashes for zlib_state-0.1.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd84a069c36dba47392ef50853d3ef2e87f34164f614caff71b8784ffcb931e4 |
|
MD5 | fa7f465c26336eaa123213b2129e0f95 |
|
BLAKE2b-256 | 9fc8091e4e4b126f3d85f593be2ca695229d19d35699182c8d643b6ac8d52e18 |
Close
Hashes for zlib_state-0.1.0-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70f78d1d7810df43315c72c3acf47e237bd8f1f0c8b17eb891e6c91f663a5ed7 |
|
MD5 | 8d3e97f6f9f0fe0fb16cfde0b427bbf5 |
|
BLAKE2b-256 | 1fc7e3697b74ea16f20bfbd5b37d83dfdf4ba55b79ab03cb7ae2b693950de26f |
Close
Hashes for zlib_state-0.1.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b333c13749553259b7b2c2bb9362437bf6081067fed9dde646b1ffcf1eb0ccc6 |
|
MD5 | 5faf0c62f17dca1ae30d2528bda94219 |
|
BLAKE2b-256 | 72c49ed06aa77c382c037593bd47e734f628f3f385c846b575ba16c52811dff3 |
Close
Hashes for zlib_state-0.1.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ea1b0d6fa6e4794d21ed4cf4fc0f10b29bd6d971a17ecea104f5fbf3b5814f9 |
|
MD5 | 12df9fa162286e0aceeba20ab6cb92cd |
|
BLAKE2b-256 | c6db402d3ec1079f5f3c3dd89a69b59ec317d57c4faf1e0329c90fb3883e6513 |
Close
Hashes for zlib_state-0.1.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9dd83934baa71a488c5509cfc15518d64efefcf9e8e4d864a0cf28effcf6059 |
|
MD5 | e63ad3a47b1f6cac7267f42f95552945 |
|
BLAKE2b-256 | 3b20f01214add8b08daa77b81961670ae86938b68d523d4e474ca825acd82faa |
Close
Hashes for zlib_state-0.1.0-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f8ecf91805f0d1aff2760fb3dacf510cadffa29800ffef4f591c849d41a9b47 |
|
MD5 | 6c4859d4504563553e97bf3105fc113e |
|
BLAKE2b-256 | 6f5e54076d6832a788911611eda1408e3060da926bd3f494d6b76dfa42e00dd9 |
Close
Hashes for zlib_state-0.1.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e2c9029004fb162415860b0e5b5ddc777daafcefd1d1a820b03e442751c4dbc |
|
MD5 | d442caaa6b3456a4464067a391edb469 |
|
BLAKE2b-256 | 0e8fab3bd8dc85bc8bb8672c65ed46c68d5a9e5495281dad6de152af41d6368f |
Close
Hashes for zlib_state-0.1.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 355dfba8811a7e053dd6c53c17b94d2ead122f05a90e867d7e810308be5d8267 |
|
MD5 | 20d234dbbfcb737aa3ef404325b084ea |
|
BLAKE2b-256 | 466631c5fc67231cd6d2b82e698c0e35e399cc946aa64b3ecae619897442fef1 |
Close
Hashes for zlib_state-0.1.0-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c778b56afc61c5bc783ef6754e77dd74551f7df5ae96af9dc314be8b931b62d2 |
|
MD5 | 400134229ea0af7f2542d35b584542b5 |
|
BLAKE2b-256 | 97ad514158899cde4e8957a7814eb6a9d2818c9211e1fa7573ee23e8f5790cce |
Close
Hashes for zlib_state-0.1.0-cp35-cp35m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1d44259a6d5cae18635de1979cdf6f6a9723374b4fa3e6b6968bb3ca99efc6e |
|
MD5 | 19f2202d0af6c1cfd00ebce35fbef6ed |
|
BLAKE2b-256 | 6a035262c38d31bef91956feac7ef5b0122a57de53cd56f405ef85777ab0ca63 |
Close
Hashes for zlib_state-0.1.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99d1ef73296b4e23e86203461aedaec3eaebd9459b932d83a528e834f74d383f |
|
MD5 | d1e4f3fa93638efd9ce83ebd00a8aa0e |
|
BLAKE2b-256 | 6f16f5b039a58de87da1f2ef852335f3ddefd934f4635a8d2b96a2f9f5f2ddd0 |
Close
Hashes for zlib_state-0.1.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2f0001241c359ca00f1ed2a7c69ed6a5b8ba82a078763a414dfa110e6b1b3fb |
|
MD5 | 65a5ba0269968c292e798abf2654d3a6 |
|
BLAKE2b-256 | cae7d73804c73ddd8579a66641fcb46d071cb83bd861825ed9674db0ba2d72a0 |