Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-132983: Add documentation for compression.zstd#133911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
49d9c30
62ef4dc
0b154b1
63f963f
cfe0590
5115b4c
4ab7fd7
5eb5efc
987bd27
615ed7f
0f7bc05
44173f3
8bd5500
24f3761
d04ce4f
e61e9a1
1149832
71ed7c3
2f895dd
f25e6e7
9ff6320
daa9df1
b3fd3cd
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,18 @@ | ||
The :mod:`!compression` package | ||
=============================== | ||
.. versionadded:: 3.14 | ||
..attention:: | ||
AA-Turner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
The :mod:`!compression` package is the new location for the data compression | ||
emmatyping marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
modules in the standard library, listed below. The existing modules are not | ||
deprecated and will not be removed before Python 3.19. The new ``compression.*`` | ||
import names are encouraged for use where practicable. | ||
emmatyping marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
* :mod:`!compression.bz2` -- Re-exports :mod:`bz2` | ||
* :mod:`!compression.gzip` -- Re-exports :mod:`gzip` | ||
* :mod:`!compression.lzma` -- Re-exports :mod:`lzma` | ||
* :mod:`!compression.zlib` -- Re-exports :mod:`zlib` | ||
* :mod:`compression.zstd` -- Wrapper for the Zstandard compression library | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -138,10 +138,9 @@ Reading and writing compressed files | ||
``'rb'`` for reading and ``'wb'`` for writing. | ||
.. attribute:: name | ||
Thename of the Zstandard file. Equivalent to the :attr:`~io.FileIO.name` | ||
attribute of the underlying :term:`file object`. | ||
@@ -542,8 +541,7 @@ Advanced parameter control | ||
compression technique used by zstd, resulting in higher compression | ||
ratios but slower compression. | ||
.. seealso:: :class:`Strategy` | ||
.. attribute:: enable_long_distance_matching | ||
@@ -684,11 +682,11 @@ Miscellaneous | ||
.. function:: get_frame_info(frame_buffer) | ||
Retrieve a :class:`FrameInfo` objectcontaining metadata about a Zstandard | ||
frame.Frames contain metadata related to the compressed data they hold. | ||
.. class:: FrameInfo | ||
Metadata related to a Zstandard frame. There are currently two attributes | ||
containing metadata related to Zstandard frames. | ||
@@ -712,34 +710,38 @@ Miscellaneous | ||
.. attribute:: zstd_version_info | ||
Version number of the runtime zstd library as a tuple ofintegers | ||
(major, minor, release). | ||
Examples | ||
-------- | ||
Reading in a compressed file: | ||
.. code-block:: python | ||
from compression import zstd | ||
with zstd.open("file.zst") as f: | ||
file_content = f.read() | ||
Creating a compressed file: | ||
.. code-block:: python | ||
from compression import zstd | ||
data = b"Insert Data Here" | ||
with zstd.open("file.zst", "w") as f: | ||
f.write(data) | ||
Compressing data in memory: | ||
.. code-block:: python | ||
from compression import zstd | ||
data_in = b"Insert Data Here" | ||
data_out = zstd.compress(data_in) | ||
Incremental compression: | ||
.. code-block:: python | ||
from compression import zstd | ||
comp = zstd.ZstdCompressor() | ||
out1 = comp.compress(b"Some data\n") | ||
@@ -749,17 +751,19 @@ Incremental compression:: | ||
# Concatenate all the partial results: | ||
result = b"".join([out1, out2, out3, out4]) | ||
Writing compressed data to an already-open file: | ||
.. code-block:: python | ||
from compression import zstd | ||
with open("file.zst", "wb") as f: | ||
emmatyping marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
f.write(b"This data will not be compressed\n") | ||
with zstd.open(f, "w") as zstf: | ||
zstf.write(b"This *will* be compressed\n") | ||
f.write(b"Not compressed\n") | ||
Creating a compressed file using compression parameters: | ||
.. code-block:: python | ||
from compression import zstd | ||
options = { | ||
zstd.CompressionParameter.checksum_flag: 1 | ||
Uh oh!
There was an error while loading.Please reload this page.