Skip to main content

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


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.12.tar.gz (9.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

zlib_state-0.1.12-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (24.1 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

zlib_state-0.1.12-cp314-cp314-win_amd64.whl (13.0 kB view details)

Uploaded CPython 3.14Windows x86-64

zlib_state-0.1.12-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (22.1 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

zlib_state-0.1.12-cp313-cp313-win_amd64.whl (12.8 kB view details)

Uploaded CPython 3.13Windows x86-64

zlib_state-0.1.12-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (22.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

zlib_state-0.1.12-cp312-cp312-win_amd64.whl (12.8 kB view details)

Uploaded CPython 3.12Windows x86-64

zlib_state-0.1.12-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (22.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

zlib_state-0.1.12-cp311-cp311-win_amd64.whl (12.8 kB view details)

Uploaded CPython 3.11Windows x86-64

zlib_state-0.1.12-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (21.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

zlib_state-0.1.12-cp310-cp310-win_amd64.whl (12.8 kB view details)

Uploaded CPython 3.10Windows x86-64

zlib_state-0.1.12-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (21.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

zlib_state-0.1.12-cp39-cp39-win_amd64.whl (12.8 kB view details)

Uploaded CPython 3.9Windows x86-64

zlib_state-0.1.12-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (21.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file zlib_state-0.1.12.tar.gz.

File metadata

  • Download URL: zlib_state-0.1.12.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for zlib_state-0.1.12.tar.gz
Algorithm Hash digest
SHA256 ccbb06321daf165b022aa4d22d62effb7df76f55035d50bbe8b93696db416cf0
MD5 2b35c37e542ec1635ea8c4f525edc587
BLAKE2b-256 53f2c1b3dfb76ff3eac8eb2a96eb1e8e05c13534c73f0d1d582dfadadb5a863a

See more details on using hashes here.

File details

Details for the file zlib_state-0.1.12-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zlib_state-0.1.12-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 360054c4c640b4e74a807a5739bcf99451b410892f15723d4a1cb56352a43e54
MD5 c2404b79fad3a6fffab9174f2e598834
BLAKE2b-256 59a4f59dc9cbfc704cf5357bbc40d5ae0faf9358fe4b464276332e14df90e38e

See more details on using hashes here.

File details

Details for the file zlib_state-0.1.12-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for zlib_state-0.1.12-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 e3ed3230ae87770b3a809f987aa21d37a9063b102d3b9ef553fa871eb900638b
MD5 36fe44792f14a7b8d78141caa9887434
BLAKE2b-256 d4b24980c6a03180c25e5ff10ba068fde1ec81a42728ea42f4dc3cae3f21a82b

See more details on using hashes here.

File details

Details for the file zlib_state-0.1.12-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zlib_state-0.1.12-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d743776b126e3bb7843f0f4fa428954ea16d9c29dfa933cf3e6085ef7ad6392c
MD5 5a5a72fcced0e4fa15f419815cce163b
BLAKE2b-256 d0eafd777b721efb8df2a7910cdfa4c551c26c2a2667440148b03fb6227d10b1

See more details on using hashes here.

File details

Details for the file zlib_state-0.1.12-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for zlib_state-0.1.12-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6466325e9e20a7e30b0c0291024fef2cb80a534324393609b5b30db42c065d1b
MD5 ce3e4887ad5872b9842c140faaccb5ba
BLAKE2b-256 310d76a524ee21b62cecd00c469d5cf1093ec2310684ba9e2cdbf6d323681d0f

See more details on using hashes here.

File details

Details for the file zlib_state-0.1.12-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zlib_state-0.1.12-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 940674e4b4d6c4df7e3be75be48c6ad1f07c0f42cab2d0b5655f67b8f0532073
MD5 8901fe8478b72d4f2e19df80a86397a9
BLAKE2b-256 6c09bafb78fbd0471aadeb96c4d79dc76b25c172153935563357b250c1f0d80b

See more details on using hashes here.

File details

Details for the file zlib_state-0.1.12-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for zlib_state-0.1.12-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f1d38461b99af652575f50cfc334f0958dbfef541679199f4ef09877cf9509c4
MD5 cb83675eb488a9132e94c052d6326e23
BLAKE2b-256 da7d47646b78823a16d6dc055b89a16bc04b80f9df979cfa0765470a2bed8417

See more details on using hashes here.

File details

Details for the file zlib_state-0.1.12-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zlib_state-0.1.12-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 91a0b6c7007ed4bd3162ac33114ceea62c28b24cd585efe3a10d2626576b445a
MD5 60cabc7f226eb39bbf583fc6fc754aa4
BLAKE2b-256 bb20b26f462b948ea8e66f878502c9594a32eda4e8ad96d9943667f4fe0f7a91

See more details on using hashes here.

File details

Details for the file zlib_state-0.1.12-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for zlib_state-0.1.12-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 572a2a7984eba730cec204a906fb8d41fc1022b4818797c97c503acb213caef0
MD5 ee2996a4823817008594ddb2ca7ed40c
BLAKE2b-256 2602fa5b6523a4cc3f52192a77a4f3d58563b200643d2408ed29e9808b17bd9b

See more details on using hashes here.

File details

Details for the file zlib_state-0.1.12-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zlib_state-0.1.12-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1e37d5877273a7cfdc0f1a30c7efe50c95e617d1ff716ac88e2ea7589088a88e
MD5 23107ea91999ce0a0ae842479b8928d8
BLAKE2b-256 ccbfc1c1eaab3a127f58c27139901eaa5e16b779d4a6896719a09d239887d8da

See more details on using hashes here.

File details

Details for the file zlib_state-0.1.12-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for zlib_state-0.1.12-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 25ccf55445d9ebb6e3b89606a50da984a6f9a84ecfe52bb9841a925701ec5b53
MD5 ef8f3b98b4944496036022c8d080e22a
BLAKE2b-256 8d6ea10048a6246efd69b96eeadc46a9bd9172aea8562ce6e9009e3bffd49cfd

See more details on using hashes here.

File details

Details for the file zlib_state-0.1.12-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zlib_state-0.1.12-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5ba18c237c0c8176c6a68965a990f32980cc734f51cee16c997fcf83908505ce
MD5 53ae2e1c310559f2d5a0d628cd502555
BLAKE2b-256 6ca694a37b05fccfd3ff506535fb2537ea4e2a49e7eb8db761b4d826aa26bf79

See more details on using hashes here.

File details

Details for the file zlib_state-0.1.12-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: zlib_state-0.1.12-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for zlib_state-0.1.12-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d076cdbe4e47e8c796166b63c4ac5ab9d4f410020c1870b572815c2671fb7b51
MD5 bd386ebdbc68fd759d15c7a24e9b8b33
BLAKE2b-256 5521464e9aa02d23aae4abb21a269ebfabf92d9cdc4f5e2f1684860e07a67b03

See more details on using hashes here.

File details

Details for the file zlib_state-0.1.12-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zlib_state-0.1.12-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8a3981388a25877cfdd2b7f99d7c342f5fe09cb4b9a31f7e64a8f3d0bfae1f8b
MD5 268815932f251de2d3fc7272a129dcd7
BLAKE2b-256 c9d0008b34ce142f8b3c1c3878cc1cf4a67aaeead085dcd6a822077045d7ed92

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page