Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zlib_into
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dataAnalysis
zlib_into
Commits
3f26e9a8
Commit
3f26e9a8
authored
2 months ago
by
Thomas Kluyver
Browse files
Options
Downloads
Patches
Plain Diff
Add README
parent
cafc3212
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#161747
passed
2 months ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.rst
+34
-0
34 additions, 0 deletions
README.rst
with
34 additions
and
0 deletions
README.rst
0 → 100644
+
34
−
0
View file @
3f26e9a8
**zlib_into** allows Python code to compress & decompress data into a
preallocated buffer.
The `zlib module <https://docs.python.org/3/library/zlib.html>`_ 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:
.. code-block:: python
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
<https://docs.python.org/3/library/zlib.html#zlib.compress>`_ and
`zlib.decompress <https://docs.python.org/3/library/zlib.html#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.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment