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.1.tar.gz
(8.9 kB
view hashes)
Built Distributions
Close
Hashes for zlib_state-0.1.1-pp37-pypy37_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a496d19b214f3fa215b79e2b444564c0cb33c2e852b0601afa6e931868175e5c |
|
MD5 | b8d1f62707a392488f433965f44fa4bc |
|
BLAKE2b-256 | fd68604401310eab318d4118327c043453d21116226dea8b260e580e8bdf9b8d |
Close
Hashes for zlib_state-0.1.1-pp37-pypy37_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f8ac01c1e1273d26189fa6e34e9aa6183aee3a14fd2ab911efc105ec602067b |
|
MD5 | edebe18f4186d588d13d6f9a95ba8ef2 |
|
BLAKE2b-256 | a29750c7a359bbaebf4817dbb6e34f9bd3175dd99d2bc764e5604ee92db27dab |
Close
Hashes for zlib_state-0.1.1-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03e09282bbc39acb588631450225517b502fa691108972641b58334e02b13df0 |
|
MD5 | 7cfe5d573183c4dd091679dfa374bc3a |
|
BLAKE2b-256 | 988094d1ec5e0e03b278a19aea4ff7a58eb9322a570ca2d19cb105be65c142dc |
Close
Hashes for zlib_state-0.1.1-pp36-pypy36_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 059aaf5661406c3e79808e96a344fa5d53d9c8c4261520ca88f0f50566a00f50 |
|
MD5 | 67d7e62d5b7aa3a37b9af188d432b1b8 |
|
BLAKE2b-256 | 695eb9c83be841ff92c69cf535d52ffa8796f519e5c51325f757272aabab3267 |
Close
Hashes for zlib_state-0.1.1-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c49c9f61a4a2411a60fdb2a30346a1d8f0b0190674c6359c123e83ec9011583 |
|
MD5 | 65c0f4023ff6a77dafa4d58ec78e2bee |
|
BLAKE2b-256 | 90fb98312a629da3547e486b1d586d3973c88dd1881eb67d36f0419fa060ffd9 |
Close
Hashes for zlib_state-0.1.1-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 258c788bf8d5099b0f0946215900517a9009325438599a3de68903dfbf97997f |
|
MD5 | 2d5cd86e9d961df5720e1157a8aa7ca9 |
|
BLAKE2b-256 | 8a872fda4cc7661acd593fa75cf18c4b41531c5477cbb3722c51777f114883a5 |
Close
Hashes for zlib_state-0.1.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 133bbdc3f4706848601aae6d5b261b7178d6c2f6f4731044a2252e24ecc1b83b |
|
MD5 | 25e1d572d00713b846c766dc26fdd80a |
|
BLAKE2b-256 | 9c668c9ff75d8f5687a890a1caed7e8a27de54eddefcf6ca12d9e83966dff817 |
Close
Hashes for zlib_state-0.1.1-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9697346d5500a9694868826e5a98b8eec46b61fadfe59aa9b6a377d34742e6a |
|
MD5 | 18705a1f75b3c4832beb131822abd0a2 |
|
BLAKE2b-256 | 76af25b0493b83cc30d06c89bbc921561236b98bb8eaa4da3ec1b305f13ba1e6 |
Close
Hashes for zlib_state-0.1.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 054742ee9b8915a59aeb2e2c85c2eaef94b15f70393d6026d2051e2ac3a55dac |
|
MD5 | 6591404ade308695dc7dba8c4f7a1096 |
|
BLAKE2b-256 | 52b3681612da0d3b5ef6bd43305252a34667a4a7069d0d7874faf2ca5cbd3f19 |
Close
Hashes for zlib_state-0.1.1-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b1c0dbeddd0c20a74dcb8ed83264ee339b0dec8aa410b723f081e1ce4c7dc09 |
|
MD5 | ad1e8ebce3edb5e43631717e633e5a0d |
|
BLAKE2b-256 | aa2488fc9c7fae2c26cf4446ec2faa3246d13303ca753f8dccd9c39675cb1322 |
Close
Hashes for zlib_state-0.1.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c25d672a19a4effe5bab6214123cf97e4d7da86baccb4a4882c6b00aa6fb0465 |
|
MD5 | 62c51642f4d1f07d40ab0b3fc2163527 |
|
BLAKE2b-256 | 016c6b0bebf42cd5e93d70739116d3ebe0f6444372b718cf7629771888fcf369 |
Close
Hashes for zlib_state-0.1.1-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3857b8281e0623acd45e1c74708725cf39d17e4f3dd1cbe8f359f41725850bda |
|
MD5 | 95f2e5c8c655d8f971ace734285a04ae |
|
BLAKE2b-256 | a57823a99b7fe9b4382e6cc8a809f459dc7b0e93a9122312b8713bc2c9b24cd3 |
Close
Hashes for zlib_state-0.1.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b7d62eb29d4c57d09ee4897ac5ce9f38b184ba431d78ce3bee6a37e5f5a13f0 |
|
MD5 | 04d6a99718b534ebdc20e6c5c0667920 |
|
BLAKE2b-256 | 9804c12f4233c201dac5e1c5ed5ca4ae2ad401140bface353d386c6f89326604 |
Close
Hashes for zlib_state-0.1.1-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 808a0f5b331de3c2ea67e28753a3e86d25134a94dd8fbf0124fbb5b5b5809329 |
|
MD5 | 4090466fbd0f776423cdb601bd3deb97 |
|
BLAKE2b-256 | 9ef5c7a6cdbf931767167b7779f5df434959fc70a8543165db1170d14ffc7736 |
Close
Hashes for zlib_state-0.1.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 614b4eee3cd8bc048fb56b361dc79c028670881577e9a21277a4742dbd0d95e7 |
|
MD5 | 6bb1678d9a74ec4d35b7d3bbe0576bde |
|
BLAKE2b-256 | f9ecebd9cc6845c881ea39148eee826deb2d80f198c432c8d55053b859bece3f |
Close
Hashes for zlib_state-0.1.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 345fd3d99ef49c6f86c3dcb88d4b486f0f49068cb206f5afa8aef730af1a1f02 |
|
MD5 | 11099a87d9bbddfeb17daf29225574c9 |
|
BLAKE2b-256 | 850ec1de56dbf6a240b0973e46aaf517538c154ea03970b3574d9838eea1d1f2 |
Close
Hashes for zlib_state-0.1.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c82c46891279e05ba643ac8c72322c3508d1154dcb158cab565adafe8c94fe2e |
|
MD5 | 37101448a11898598e50fcfd05222c8b |
|
BLAKE2b-256 | df596bf6be3a35d26b1ca37bcd497b2978bcd078c039c459c92aa6ae8e60f694 |
Close
Hashes for zlib_state-0.1.1-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a9616f59035133e0b68e92464728a472666c27ae886f3fe322b26b29d7577f1 |
|
MD5 | 6d248725953cf7db8011f43c499ce8f8 |
|
BLAKE2b-256 | 41bd5b6e6761e0439e5ef8071ed6433e98bdf65cded80d0cb7ba83827f03a940 |
Close
Hashes for zlib_state-0.1.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c99405ecc58f4c5f22f71cdf7f56cf644b8e3880b59cb54cf122fb4db3a8e6b |
|
MD5 | 55781d8b0a1451082818219f2409257d |
|
BLAKE2b-256 | 8fdd568b5e9c7676544f71d31aff11ad1aecb1eed3d015407ce308b98a5f361f |
Close
Hashes for zlib_state-0.1.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f99e1fb961ccd44c5dba88fae8f475ea0f2b33bd150d21f9d1159e51eb2671ea |
|
MD5 | 97d7a0c510f63b0f234114cce8878e28 |
|
BLAKE2b-256 | c38b7b12d071471976929fc3c897ccd50713b7d9208a4d1abb1da047c8e0bc7d |
Close
Hashes for zlib_state-0.1.1-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17cc7b020ec1c77285c3dd872a505aa3c0d60da0d5b3365817e7ac1f4ceb7a32 |
|
MD5 | 64b2b1d5a7135e3978b6c2a68e6501c7 |
|
BLAKE2b-256 | e035f33212b5e3c83cd27a03a330c5473c7e5ba4b24ccbce7e8738f0d0967094 |
Close
Hashes for zlib_state-0.1.1-cp35-cp35m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 827788e7ebe0cfb3490187551a682b4c8145796570532df64487c34430880cc5 |
|
MD5 | c90c733f92b32d50f5cf5a18a80c65fb |
|
BLAKE2b-256 | 4d24fd1f305c35a50ad0899324b3533fbe1a6b838f1d897eec97dbbf76901d3f |
Close
Hashes for zlib_state-0.1.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bfb7b4ee66996c94d374ad6bc49a73e521a6378a849b4f9be03f07d83bd3cc6 |
|
MD5 | c60e69be5af878aa8d5cdc4ae313ef0f |
|
BLAKE2b-256 | 400a559bb0aa6f19af39dea6f73636b258e1d85cb47f9b544780390e250024c4 |
Close
Hashes for zlib_state-0.1.1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 423f82592733e66d986aae7460e0b0efc7febea5d9ee5d1d12fd1fdaa9d1e511 |
|
MD5 | d03fb878c0964a39050d901076b87af4 |
|
BLAKE2b-256 | edb39876679ab523bb0ad2e2418bfd0c0fb15f4f7c510c14562a3fe8d9a9aabd |