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.6-3.10.
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.5.tar.gz
(9.4 kB
view hashes)
Built Distributions
Close
Hashes for zlib_state-0.1.5-pp37-pypy37_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 127fe425f727eefc4a5aff548ce98050460b27bc82c2209a54c583bffcae9c0c |
|
MD5 | 813e79f49fbb6178c526b46703603626 |
|
BLAKE2b-256 | 9573d826212a04dc9e64c84f2c320643df0b7a4eba2692a75eaecc07877010aa |
Close
Hashes for zlib_state-0.1.5-pp37-pypy37_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8f2c3a84c5a4f400297521f2e8540d59572c721a62fc746db9afbdd4c71e3f9 |
|
MD5 | 6ebd6c46d60d146709f0639447899bff |
|
BLAKE2b-256 | 2561b9604e5b89d6ccac337843d6370b6a2c8318c4bd83f9c7e7e554a8c3fac7 |
Close
Hashes for zlib_state-0.1.5-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70a0094b7b4b419ec6569c8cfaa64b3e85218c1a5a9fbf474dbf1c0db3ef6712 |
|
MD5 | dac1ae18237d34f7376913581d4293d1 |
|
BLAKE2b-256 | 5cd25824fb59a30cabca09135f0f5517801979c5dd91885cdbe33f832cbb1668 |
Close
Hashes for zlib_state-0.1.5-pp36-pypy36_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 482869e942e702ae22d59e2d9efc5486f6b35abcc38d1d7fcfb8cc34b29e93f7 |
|
MD5 | d787faf34a23346239965398aaa63277 |
|
BLAKE2b-256 | b12c3c4645c471f4a19697b0f625aaa59643bece54a7cafa96b6c9b2b7ffb554 |
Close
Hashes for zlib_state-0.1.5-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbcb63d12509e739777ce855d32c3ccb5e434301cce9ed6174944700d986042e |
|
MD5 | ccb9e59cc07ab7c009061a3825fe9952 |
|
BLAKE2b-256 | 512e10bb738db8a3f57fa288b043b68d228237651b99a1934819f36a8dd4a99a |
Close
Hashes for zlib_state-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2be1f982341c02fe0eb164e3dec9b29976bf3aabd046b094461ee51a573db08f |
|
MD5 | 3ef2a1ae19a82e6afce026e9ab2cbed8 |
|
BLAKE2b-256 | f82807cee8a217b3ddd1fa945f32a68e8987f2fcbfa318e2b346f20136d8cfce |
Close
Hashes for zlib_state-0.1.5-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c32530ec7122e9ad9bf953861a5e25824acdf5d942c962d1812fc83b29cc06b7 |
|
MD5 | bc0dad0d1f66d3fd731c3e1b81160ad3 |
|
BLAKE2b-256 | 04e7593965bec43f9946fdd32299058fa66be35bd4a67a383097d45e0d20fc54 |
Close
Hashes for zlib_state-0.1.5-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d7cadc020996791ea0baa55f0987cc7b52d932af1df1ea21fe6299f614f6339 |
|
MD5 | bae5a206f858021ba02f7906c3b1832c |
|
BLAKE2b-256 | fc3828911549dcb259a81007c68880ff27f302372b67a5359e8f6edff4805641 |
Close
Hashes for zlib_state-0.1.5-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ba5f1100675018521a4e8d514bb680a37d3b91c7e2ca7305b8647ec8c9261d1 |
|
MD5 | 294ccd96c6c780fa73875d5a74a6c2f3 |
|
BLAKE2b-256 | 6fd58d58e3490cdddc363fcf72682660e54a18b45aab9c6a4cd9b9c189c29633 |
Close
Hashes for zlib_state-0.1.5-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ebb60cd73e1f18a43e3b08127496ec117d8eeb7e2859c3783e519d1b04fd994 |
|
MD5 | 605434a816815e78581c593f8f722e69 |
|
BLAKE2b-256 | c89730f2c92c69554acd198a3b54c4cab4997ab766c6b94c26142e47b50195c8 |
Close
Hashes for zlib_state-0.1.5-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09d0f035314a0dc3d7503b186a4a6262fe5d1abd3d63e74f28352c140cd35c2f |
|
MD5 | da06b91ec82a4e02f3a1590ef9818199 |
|
BLAKE2b-256 | cf187b129382befbd9c1a8746ab3eac628810336c0b65699d3d6948ae60b4aac |
Close
Hashes for zlib_state-0.1.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae831bf18ab4e26a6828236821e2a426e7c06ec29ac8ea7291ddd03d23c5c616 |
|
MD5 | 809afe55c051394885777aeb25242abc |
|
BLAKE2b-256 | ce12512597b7f4af29700dad71f359432b932e5ffa681ebe5d6ec44d4f88275b |
Close
Hashes for zlib_state-0.1.5-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab1bbec2aab3e4b4503f74c05fed3e158ff3af5e783f738f9fd566589b27f1bf |
|
MD5 | 0cbf1813255c3f8a14eece60a7775dc3 |
|
BLAKE2b-256 | 4ae817099d3f7b7188ff689d1b5428975e311644e260c1f8345682565bfa35c8 |
Close
Hashes for zlib_state-0.1.5-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd769e209b5d5ca9cce02fb2c39788ff1e76c5782c8a3b625b04a1fbb24e7cb0 |
|
MD5 | 92a7eb3f831bec48008515201bcda6a4 |
|
BLAKE2b-256 | 215df94e4427dc82cb7f0b08e81fea20ed2d83531abbcc238146cc4b1be19341 |
Close
Hashes for zlib_state-0.1.5-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7d6f2b9ec2ed0d4379866896181fb34d704adda6f1930eae93118a33481925a |
|
MD5 | 59826ea19d05e6588d36f8fa80a8d410 |
|
BLAKE2b-256 | 986ece50c5ad7ad3492876dbd0c968551b8b932eb5ccdbc6192eb1de069d4c29 |
Close
Hashes for zlib_state-0.1.5-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50f8f417975b6099257a128291cf51244fb3b6bc2ec99959f43c77709de50850 |
|
MD5 | 6b5327f0710d4d5107424841831082c2 |
|
BLAKE2b-256 | 7aae1306df7d83dfa04ca9f46974b10a73f456564824be2234387f8c8ab468ab |
Close
Hashes for zlib_state-0.1.5-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7c8934b69fea29cdc639b775f932fd49c786d2430b918bf62248f29d00c04c0 |
|
MD5 | 802dd0b0678dbce481bf3338e9b9ba37 |
|
BLAKE2b-256 | 5b438f759738837ac4296fb5122fb7a99058a5e4ae0f7ba47b3f282813f31e18 |
Close
Hashes for zlib_state-0.1.5-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 025dfde0e67a1b7bc5eecc9d0905cedd9a4e42088e99fef158961e33173bed7a |
|
MD5 | bd70a39f132414a10abddb9e6c8c0970 |
|
BLAKE2b-256 | 7241c45ab9180baf33efab7c2920da365077780f0976284b912de5d5172b67b1 |
Close
Hashes for zlib_state-0.1.5-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0797c4ff0eb4bb1c94b8f6a816cfa26422426b4251de79cbffd849a8bd6a5ef8 |
|
MD5 | 827236f65d1d3680640499bd50fd8160 |
|
BLAKE2b-256 | 2ea6b04837b91400412b823777e759291e960071d487a8953ec2ea45057630d7 |
Close
Hashes for zlib_state-0.1.5-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6026902f69f6f6dab66a67703ee27a4bfdc29646b7e1e787f8672915e853ed1 |
|
MD5 | e394e1c02284f2d4c56dc8e44d538402 |
|
BLAKE2b-256 | 18e9fda2a64a3b0884c90ee26ebcff4ba69275ba5272f8ad737bf6b9db62639c |
Close
Hashes for zlib_state-0.1.5-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4885c4956034283241b1ee1c9bd0b8fca3decdaa002fb126b6390603d2897de |
|
MD5 | 20851671021b75be7e4862ace30c59ff |
|
BLAKE2b-256 | c1da059efa5c74b853230afdf20d8f240f355c3bdf962c79a35495985bc92ba6 |
Close
Hashes for zlib_state-0.1.5-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db6b49d5b8ce22eaadce5be4e838748c14c60b050f9494df0dcb73de87ec1f62 |
|
MD5 | 7c09d50cd7de673ebfd01e7fa2fec875 |
|
BLAKE2b-256 | 0a3bd336697da9dacac6d1bd848fed8b025ebc9c29f00e53112278bc98f76a80 |
Close
Hashes for zlib_state-0.1.5-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 016f663f1da16cc241554258339048c747626f4546dcb4779b0c04d6840c6548 |
|
MD5 | f0f74220bad68a33fb034ce9eb9c01b5 |
|
BLAKE2b-256 | 28780dd58eccf60903c2a25719cd34ce02a044912d37cf66a2f62ebb57622cf2 |
Close
Hashes for zlib_state-0.1.5-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78bfa5e89eecf3202adf91b34dda7763c3eed08bf9ef87cfc5ec995966f2d261 |
|
MD5 | 1b54c9b9372f8e9afb888b27340ea933 |
|
BLAKE2b-256 | 26a702ba558cd82f59184513bcc223598aea168eb0adf3dbc7b922cca3a681a8 |
Close
Hashes for zlib_state-0.1.5-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59e240056ab158ad1a9e8b054016fd20596c44131195bbe4702f485d2c9879fe |
|
MD5 | 5ac954c66fe0832b55eb1f95c2cbfb6b |
|
BLAKE2b-256 | f64b79b4045c84b3f7fc3ae0e4ed11f49a4db4932d0f33836ea6a9477f1f58ce |
Close
Hashes for zlib_state-0.1.5-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 391bcc0eff3e4e41173fe749412a5339b09f12cce420ba8b555bd2116c31d101 |
|
MD5 | 19bbe556e5c32837a4213d43ff4a2390 |
|
BLAKE2b-256 | f9034556c09eb810f36bd2cd44c71e2155055d40af0c2578cb0a51067a650767 |
Close
Hashes for zlib_state-0.1.5-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44b5780874f9bed99eba380c3a9bd40519c405cf44e8d9801723ad9672dca9d9 |
|
MD5 | 51a5daf0114d81041cab1f8374765b51 |
|
BLAKE2b-256 | 4bd56d9bbab00e314f9e4c8c40ab7797a0dd40c014747435119f6cdd1b363e35 |
Close
Hashes for zlib_state-0.1.5-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f580511aca4979fcd54fb15a58209baed84588a94a86c5df8eee567a3fd26b77 |
|
MD5 | bba56bd074ca17598a402ae20660b82d |
|
BLAKE2b-256 | 078c9efa8e84dbd49e26a08a6c737a4a0083ab6a6fa30ef6471934e1994d3740 |