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.9.tar.gz
(9.5 kB
view hashes)
Built Distributions
Close
Hashes for zlib_state-0.1.9-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3cdbffc1808590b03eb656f5eda2fd83f069e345ed0fdab90681252ab64b7ad |
|
MD5 | 5aa65023752e2cb02c0e7ab520e03cf3 |
|
BLAKE2b-256 | e20418fa47a4c4201c16d153e7118873869b1982c126e9c69ecf13a32f19776a |
Close
Hashes for zlib_state-0.1.9-pp39-pypy39_pp73-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c27962a41070c863a9464a4e663df7716feb42cf28bec3dbafa35c68f7bd1b0 |
|
MD5 | f688504721173ed4cb966972fa23d69a |
|
BLAKE2b-256 | 51c1c6c33e9a2f4ecf5d8e9af725867275b7f0beb306d41ed628686a7984cb7e |
Close
Hashes for zlib_state-0.1.9-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8773ff5130999017178bdc52bea27d48eb9c78d2f113547a317474a5d24665e6 |
|
MD5 | d3f1fc3249661ff79eb585ea6c2f1556 |
|
BLAKE2b-256 | c2bda5b350bbfb1891f6439c7acf2fb4a12acf7e84e107d31ffb2ace77f3bbe9 |
Close
Hashes for zlib_state-0.1.9-pp38-pypy38_pp73-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b697d58ef519dbbe76361c0d37a605f599660119c2ddac70811995ebdcc8cc20 |
|
MD5 | 908702b7bf270354641e3aec4fb95539 |
|
BLAKE2b-256 | 943ccef9b38d6119ae416af048b9419a7e7acda94619f3a2c8e90069b56a38a7 |
Close
Hashes for zlib_state-0.1.9-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f76bfc69636b24c26521bbb2bacd26a3826ff57112d0b7801662a122ea98bec1 |
|
MD5 | 5ec9ad5e9b96b4e2bdd7661ac7504f1f |
|
BLAKE2b-256 | 678ad7c42d19208a1e376a693074440e9cf923e6a0bb033e0cf97047404d29eb |
Close
Hashes for zlib_state-0.1.9-pp37-pypy37_pp73-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc968a30b50a5cc6c0e45a6e756f370b6530445247631dcca526108a1278889c |
|
MD5 | 30fc0863ddd5c20e248c9d86709c273f |
|
BLAKE2b-256 | 9ae2a9aa84131daa7dba30a96c0a9b0cbcbf002d01ceb58c3cbd73b2bec7228d |
Close
Hashes for zlib_state-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfc20e1be15d7a29e3b29c12860727f5eed94dd3e5d55f087a27051b5c0a0d59 |
|
MD5 | 7a552c59d606542d18aab178c81c6d96 |
|
BLAKE2b-256 | 0458f005059f410c01cf81ac0b32a79632cbeeeccf708e3a02f5cc92f68610ee |
Close
Hashes for zlib_state-0.1.9-cp313-cp313-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8686b95a3510066aea346b3baf4067f23488d1b4832b48ccdb4863e1968b00bd |
|
MD5 | 70aa32766f2e1ccffa033355bf023720 |
|
BLAKE2b-256 | 150167937968569035b7493c16b2815e5ccb0978b80b24370336018a95f33339 |
Close
Hashes for zlib_state-0.1.9-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 862b120477db67df4ad8af8c135fe134ae4051693d6a6abf1c208d9d1170d7d8 |
|
MD5 | 1b814859c80fcfdef665727ecc73c529 |
|
BLAKE2b-256 | 9988cb175ba96b1b72b424b789151341206389b913bba4de2abffc6f767cb8cb |
Close
Hashes for zlib_state-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06ed845442af6fc8ad885037b1393c02ff1554638cd43ff8718ca1fb8999b7c7 |
|
MD5 | cdc2dc46311a00ef15f9b11b68fe80c8 |
|
BLAKE2b-256 | c6f887cbda2338b5254db486804f8ce802a47a870b3f8572e757d37bd1f3d122 |
Close
Hashes for zlib_state-0.1.9-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c22bc6ea28d1cbb717e7ba8254b12da5cff0820309d7ff46dba083d2dc44fd69 |
|
MD5 | 81eba28bb6988f439e1a847f98bff12e |
|
BLAKE2b-256 | 6cae739524e41a73cb77565bcb14d30478b322bc109f6e79fc583572eb75f637 |
Close
Hashes for zlib_state-0.1.9-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdb7cdf2515d8c70c6a99a331bf8c1486b3bda77371e951961272cc9888494e1 |
|
MD5 | facacd074b1fb1f88c9f3ec7fab934a0 |
|
BLAKE2b-256 | 621aa111ef96419b7195a3a50604668fe56cb5894fdecc79befcef964da5e103 |
Close
Hashes for zlib_state-0.1.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66dd680ef5c0d21fe1e673a4c68173feeda20f7933e3468c22c44d5960ebf621 |
|
MD5 | 4272d96af9e828ab6de33e65d7b053af |
|
BLAKE2b-256 | ad4814617cfa8ec97309e2e3cabc42b3e106e9354775940dc96443e9e5f1e55c |
Close
Hashes for zlib_state-0.1.9-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bbfd191c908be2ba04319e57b4d166f9c625204c1a8c85d2eb968d9d7d14dcb |
|
MD5 | 77968a0f0aa015cd135700faafb3f4b9 |
|
BLAKE2b-256 | 47be22a0657de2e7ad230aec984935f980e77bd21706688a90ae2572de06e1d8 |
Close
Hashes for zlib_state-0.1.9-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e633bd3fb65cd8c8f0fc5870cdd40354f218f815cc7a53fb525410251f06ab9 |
|
MD5 | 9865e3600989b428677d8823049475b7 |
|
BLAKE2b-256 | ed38910748b5f788d311f43d2dabc11f0bddc173d600e0ede7f1660d78f4efb0 |
Close
Hashes for zlib_state-0.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3564eaa130f2533b87b82d0e622cfb5c25acec123e7bfe38d39db9ce6349cb52 |
|
MD5 | 7518b1b833c6bf3b52da811b561c5ada |
|
BLAKE2b-256 | be8475833ca8df9307aa098acca7ee1f959790b4e4f811242d5363908bd8c713 |
Close
Hashes for zlib_state-0.1.9-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97f45d0f80e9d7070229ecb36112eea6a17dc40053449a9c613ef837d9cb66b4 |
|
MD5 | 9bc0b795ad5de88fb985a72cb93cec10 |
|
BLAKE2b-256 | 56840619cadedd1ae873353fc2d15873bcd9be1a2a5d2f6c100006e7bc483124 |
Close
Hashes for zlib_state-0.1.9-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20811b7271c721baac2feb3f2b14aeda66e4989d6df2edc3242bab3a820e2279 |
|
MD5 | dfceadd5617a25141784e02cfeb43688 |
|
BLAKE2b-256 | 4ff62debb2243a1d804e36eadec311985eb3b4f2231e3dc79bcc1c4353d35d6c |
Close
Hashes for zlib_state-0.1.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8255a96bc6ff5964cc665e718ea1c8da4895bdc292536a32d11396d63524609 |
|
MD5 | 4bfee7bdd47e1f8d944779b1def84901 |
|
BLAKE2b-256 | b23b7c2e30d9f5ea84e4f1933a4a0d15342046807f904d9ce51d52ce0123543f |
Close
Hashes for zlib_state-0.1.9-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 001b5fb0af67e978e6d50b9ac8a1aed9d2411d8131c032eec3f02d65f23fb5a0 |
|
MD5 | 8dda0346bff73af9cb3967dbcf714dee |
|
BLAKE2b-256 | 5f5e7d9af13be105d37963ff0b6cef7932a082653182084fe5b27162806ec018 |
Close
Hashes for zlib_state-0.1.9-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45fcd1c322daac34785250a7b1d099402e62eb54e9318c952de6b527737d2776 |
|
MD5 | 6ae2dadb31013df74b0b312c06a2e76b |
|
BLAKE2b-256 | 38c176d170c1dc8c382abb1df373b5902d3ac63e1924fb2a8f11ddf3eb9c08f9 |
Close
Hashes for zlib_state-0.1.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4ceef43fde93b2626655b22a8c88768607e844ea3d2ca6429d79beeeda1a671 |
|
MD5 | e17aed8fcfb30c79f7c768ff3ba0d210 |
|
BLAKE2b-256 | 63cdf5a499932ceefa8298944de45e94647d0e5ea6e1e2c95fbb01437d6a04d1 |
Close
Hashes for zlib_state-0.1.9-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33d731a7cdeb310dbe8ae7473ae5b06b7d905c6459791356de884944f734077f |
|
MD5 | 323d1f4d37844a7e48a868247a77a000 |
|
BLAKE2b-256 | c156dc99f96bdaefb9183d9a6eb3cf57c238f2bed1024c2d8b9f4a10d1029270 |
Close
Hashes for zlib_state-0.1.9-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83d246e7c56eca91b0dfa6757617b452c80af9dfc1c26c22cae83972dc3659e1 |
|
MD5 | 33546e1fefed80cf56321386ba174bae |
|
BLAKE2b-256 | 153742a5dc94bd7ac3e9522b922e70cfa65f70e4a70981575a364e92a972b1c5 |
Close
Hashes for zlib_state-0.1.9-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2557c04013733022b14023edbf9a52000ecf5dfee530b925abe33e9eb2167ac |
|
MD5 | 974513aaf9b8554dde81df795bae2c11 |
|
BLAKE2b-256 | e6432942dc815cddf045dbfcc59cbe3c9de65b27080567d7281b0e17afde5c9b |
Close
Hashes for zlib_state-0.1.9-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2a0dec8c12a7df84435d3777f88c6fb424e5405c7151a3c219f18257f7830b7 |
|
MD5 | 538a243bce6fb64f73f1073f303e0622 |
|
BLAKE2b-256 | 86115ceb2779f554bd67941c386ac6432a4052a526a5cfb548500da1f466e7c6 |
Close
Hashes for zlib_state-0.1.9-cp36-cp36m-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e96af2f329e0931e96030a7294b52821aecfa390fee8c12dc2d0a143b1dd2720 |
|
MD5 | b95b5b300ea5dc1914aa61f6329dab77 |
|
BLAKE2b-256 | d1463d36c1ae0e64adfdf2144df36a9dd91fa1a94f3d4a25c009442f79142498 |