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 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.

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

Uploaded Source

Built Distribution

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

zlib_into-0.1-cp311-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl (23.0 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for zlib_into-0.1.tar.gz
Algorithm Hash digest
SHA256 07a24567335b68f1f68dcb0c29c85db8bbd33401bf77c878dc87766829dc2ee6
MD5 b6620d782a72cbabf0d28c53c3dbdc86
BLAKE2b-256 eed705c1757b5a9ac41d8f6f83f2205cd33b70fb915c46712199e1eea6bcf6b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zlib_into-0.1-cp311-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3100b727509756fe9ee712932d85fa5eb1e06ae0a7824184c9bde5f2e67cc6c0
MD5 f0ff63f17c0ff58288fd818d38f86f93
BLAKE2b-256 63d32281e9d6fc4659dd20cb1da83c1b0725e9f022aae40f37edb8f2c5fb0a04

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