Skip to main content

Compress & decompress data with zlib into preallocated buffers

Project description

zlib_into allows Python code to compress & decompress data into a preallocated buffer.

The zlib module in the Python standard library provides an interface to zlib, a common library for Deflate compression, but always automatically allocates memory for the output.

zlib_into defines two main functions:

compress_into(data, output, level=-1, wbits=15)

decompress_into(data, output, wbits=15)

In each case, output can be a bytearray, memoryview, Numpy array, or anything else compatible with Python’s buffer protocol exposing a contiguous, writable chunk of memory.

The other parameters have the same meanings as in zlib.compress and zlib.decompress.

This can be useful for:

  • Decompressing regular chunks of a known size: you can allocate a single output array and fill each chunk directly, avoiding an extra copy.

  • Compressing chunks when you want to skip compression if it would make the data larger: use a fixed-size buffer matching the input chunk size. Again you can avoid unnecessary memory allocations by reusing the buffer.

  • Imposing a size limit on decompressed data: it will stop decompressing (and throw an error) when the buffer is full, instead of decompressing the whole thing to see how big it is. But note that security on untrusted input is not the primary goal of this library.

There are also two additional functions:

shuffle(data, output, itemsize)

unshuffle(data, output, itemsize)

Shuffle rearranges bytes in a way that often allows for better compression of numeric data: shuffling b"ababab" with an itemsize of 2 gives b"aaabbb". Unshuffle does the reverse. This is the same as the shuffle filter built in to HDF5.

For now, itemsize can only be 2, 4, or 8. The same operations can be done for any itemsize using NumPy views to transpose bytes, but the more specific code can be faster.

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_into-0.4.tar.gz (11.1 kB view details)

Uploaded Source

Built Distributions

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

zlib_into-0.4-cp313-cp313t-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl (31.8 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.34+ x86-64manylinux: glibc 2.5+ x86-64

zlib_into-0.4-cp313-cp313-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl (31.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64manylinux: glibc 2.5+ x86-64

zlib_into-0.4-cp312-cp312-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl (31.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64manylinux: glibc 2.5+ x86-64

zlib_into-0.4-cp311-cp311-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl (31.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64manylinux: glibc 2.5+ x86-64

zlib_into-0.4-cp310-cp310-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl (30.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64manylinux: glibc 2.5+ x86-64

File details

Details for the file zlib_into-0.4.tar.gz.

File metadata

  • Download URL: zlib_into-0.4.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for zlib_into-0.4.tar.gz
Algorithm Hash digest
SHA256 767aef73038b11bccf148d618340b926d3f80b67b51e8cf484c5d563535e6889
MD5 780c2f0d67a31c7affd8758f2ada4fce
BLAKE2b-256 63b40e3cffb5cf54958646eae5952a0c2ab06856d64577126ecf577f7a936367

See more details on using hashes here.

File details

Details for the file zlib_into-0.4-cp313-cp313t-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for zlib_into-0.4-cp313-cp313t-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 deee5a23d68d52399d523df8a968cd152d36608e0698c21022a7260a66657150
MD5 38f42fbac2ec015cbd52d1a7e8145970
BLAKE2b-256 18a05bf6644130ca5191a93640363a54e10df0328f7cd6067cfd30de3979b2df

See more details on using hashes here.

File details

Details for the file zlib_into-0.4-cp313-cp313-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for zlib_into-0.4-cp313-cp313-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 bb0e693259c4210a1646883f745ba80bcc262f35ff5145865a32e9ffd28aabb9
MD5 24c10866f3bbd1e20518b4d557015c12
BLAKE2b-256 b886258a1307ca96a40c0d1408a1335213223f8f9d02dfb9562247bdfe303429

See more details on using hashes here.

File details

Details for the file zlib_into-0.4-cp312-cp312-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for zlib_into-0.4-cp312-cp312-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 58730fb59e688b3bea7cd0d26e4c27aa54b7d9aae790fcaf49353cd644859668
MD5 2e881a436e1a79261dfad1c554841205
BLAKE2b-256 33c4a8fbf7b192ede1d69e33324cc6490a8ca74dedccea25ca4d48f9a4a13c5e

See more details on using hashes here.

File details

Details for the file zlib_into-0.4-cp311-cp311-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for zlib_into-0.4-cp311-cp311-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 1ab74be2057f7662c752ffb58593df25e7ce6a2062de34e96d92495f49566bdd
MD5 d6ec9abd1e2b05b4cd5e503eb19fe2e2
BLAKE2b-256 0d95a1bfcba09892f85c556a8c2b74bb224f4fecedf1489ece6b5eac03bb531b

See more details on using hashes here.

File details

Details for the file zlib_into-0.4-cp310-cp310-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for zlib_into-0.4-cp310-cp310-manylinux1_x86_64.manylinux_2_34_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 4569ea9fa3c3dd8ddcf62a3a7ac22271b12e08f31432db8e471e7fcffe93d97b
MD5 51906d005de5ee4f10122c18ebc022e6
BLAKE2b-256 c1165f754bb51b3d4882325d40b368e4250e00fbdd2fc6f7611af14e44717b49

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