Skip to content

Commit 5eb5efc

Browse files
emmatypinghugovkStanFromIreland
authored
Apply suggestions from reviewers
Co-authored-by: Hugo van Kemenade <[email protected]> Co-authored-by: Stan Ulbrych <[email protected]>
1 parent 4ab7fd7 commit 5eb5efc

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

Doc/library/compression.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The :mod:`!compression` package
88
The :mod:`!compression` package is the new location for the data compression
99
modules in the standard library, listed below. The existing modules are not
1010
deprecated and will not be removed before Python 3.19. The new ``compression.*``
11-
import names are encouraged for use where practicable.
11+
import names are encouraged for use where practical.
1212

1313
* :mod:`!compression.bz2` -- Re-exports :mod:`bz2`
1414
* :mod:`!compression.gzip` -- Re-exports :mod:`gzip`

Doc/library/compression.zstd.rst

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
=============================================================================
33

44
.. module:: compression.zstd
5-
:synopsis: Low level interface to compression and decompression routines in
5+
:synopsis: Low-level interface to compression and decompression routines in
66
Meta's zstd library
77

88
.. versionadded:: 3.14
@@ -17,7 +17,7 @@ included is a file interface that supports reading and writing the contents of `
1717
files created by the :program:`zstd` utility, as well as raw zstd compressed
1818
streams.
1919

20-
The :mod:`compression.zstd` module contains:
20+
The :mod:`!compression.zstd` module contains:
2121

2222
* The :func:`.open` function and :class:`ZstdFile` class for reading and
2323
writing compressed files.
@@ -52,7 +52,7 @@ Reading and writing compressed files
5252
to read from or write to.
5353

5454
The mode argument can be either ``'r'`` for reading (default), ``'w'`` for
55-
overwriting, 'a' for appending, or ``'x'`` for exclusive creation. These can
55+
overwriting, ``'a'`` for appending, or ``'x'`` for exclusive creation. These can
5656
equivalently be given as ``'rb'``, ``'wb'``, ``'ab'``, and ``'xb'`` respectively. You may
5757
also open in text mode with ``'rt'``, ``'wt'``, ``'at'``, and ``'xt'`` respectively.
5858

@@ -132,7 +132,7 @@ Reading and writing compressed files
132132

133133
.. note:: While calling :meth:`peek` does not change the file position of
134134
the :class:`ZstdFile`, it may change the position of the underlying
135-
file object (e.g. if the :class:`ZstdFile` was constructed by passing a
135+
file object (for example, if the :class:`ZstdFile` was constructed by passing a
136136
file object for *filename*).
137137

138138
.. attribute:: mode
@@ -154,7 +154,7 @@ Compressing and decompressing data in memory
154154
data as a :class:`bytes` object.
155155

156156
The *level* argument is an int object controlling the level of
157-
compression. Please refer to :meth:`CompressionParameter.bounds` to get the
157+
compression. Refer to :meth:`CompressionParameter.bounds` to get the
158158
values that can be passed for *level*. If advanced compression options are
159159
needed, this argument must be omitted and in the *options* dictionary the
160160
:attr:`CompressionParameter.compression_level` parameter should be set.
@@ -194,7 +194,7 @@ Compressing and decompressing data in memory
194194
module-level function :func:`compress`.
195195

196196
The *level* argument is an int object controlling the level of
197-
compression. Please refer to :meth:`CompressionParameter.bounds` to get the
197+
compression. Refer to :meth:`CompressionParameter.bounds` to get the
198198
values that can be passed for *level*. If advanced compression options are
199199
needed, this argument must be omitted and in the *options* dictionary the
200200
:attr:`CompressionParameter.compression_level` parameter should be set.
@@ -283,7 +283,7 @@ Compressing and decompressing data in memory
283283
The returned data should be concatenated with the output of any previous
284284
calls to :meth:`~.decompress`.
285285

286-
If *max_length* is nonnegative, returns at most *max_length*
286+
If *max_length* is non-negative, returns at most *max_length*
287287
bytes of decompressed data. If this limit is reached and further
288288
output can be produced, the :attr:`~.needs_input` attribute will
289289
be set to ``False``. In this case, the next call to
@@ -315,7 +315,7 @@ Compressing and decompressing data in memory
315315
decompressed data before requiring new uncompressed input.
316316

317317

318-
Zstandard Dictionaries
318+
Zstandard dictionaries
319319
----------------------
320320

321321

@@ -333,7 +333,7 @@ Zstandard Dictionaries
333333

334334
The *dict_size* argument, an integer, is the maximum size (in bytes) the
335335
Zstandard dictionary should be. The Zstandard documentation suggests an
336-
absolute maximum of no more than 100KB, but the maximum can often be smaller
336+
absolute maximum of no more than 100 KB, but the maximum can often be smaller
337337
depending on the data. Larger dictionaries generally slow down compression,
338338
but improve compression ratios. Smaller dictionaries lead to faster
339339
compression, but reduce the compression ratio.
@@ -353,7 +353,7 @@ Zstandard Dictionaries
353353
generating the Zstandard dictionary.
354354

355355
The *dict_size* argument, an integer, is the maximum size (in bytes) the
356-
Zstandard dictionary should be. Please see :func:`train_dict` for
356+
Zstandard dictionary should be. See :func:`train_dict` for
357357
suggestions on the maximum dictionary size.
358358

359359
The *level* argument (an integer) is the compression level expected to be
@@ -374,8 +374,8 @@ Zstandard Dictionaries
374374
The *is_raw* argument, a boolean, is an advanced parameter controlling the
375375
meaning of *dict_content*. ``True`` means *dict_content* is a "raw content"
376376
dictionary, without any format restrictions. ``False`` means *dict_content*
377-
is an ordinary Zstandard dictionary, created from Zstandard functions, e.g.
378-
:func:`train_dict` or the ``zstd`` CLI.
377+
is an ordinary Zstandard dictionary, created from Zstandard functions,
378+
for example, :func:`train_dict` or the ``zstd`` CLI.
379379

380380
.. attribute:: dict_content
381381

@@ -385,7 +385,7 @@ Zstandard Dictionaries
385385

386386
.. attribute:: dict_id
387387

388-
Identifier of the Zstandard dictionary, a int value between 0 and .
388+
Identifier of the Zstandard dictionary, an int value between zero and .
389389

390390
Non-zero means the dictionary is ordinary, created by Zstandard
391391
functions and following the Zstandard format.
@@ -409,7 +409,7 @@ Zstandard Dictionaries
409409

410410
Digesting a dictionary is a costly operation. These two attributes can
411411
control how the dictionary is loaded to the compressor, by passing them
412-
as the ``zstd_dict`` argument, e.g.
412+
as the ``zstd_dict`` argument, for example,
413413
``compress(data, zstd_dict=zd.as_digested_dict)``.
414414

415415
If don't use one of these attributes, an **undigested** dictionary is
@@ -466,7 +466,7 @@ Advanced parameter control
466466
The :meth:`~.bounds` method can be used on any attribute to get the valid
467467
values for that parameter.
468468

469-
Setting any parameter to "0" causes zstd to dynamically select a value
469+
Setting any parameter to zero causes zstd to dynamically select a value
470470
for that parameter based on other compression parameters' settings.
471471

472472
.. method:: bounds()
@@ -482,26 +482,26 @@ Advanced parameter control
482482
.. attribute:: compression_level
483483

484484
A high-level means of setting other compression parameters that affect
485-
the speed and ratio of compressing data. Setting the level to 0 uses the
485+
the speed and ratio of compressing data. Setting the level to zero uses the
486486
default :attr:`COMPRESSION_LEVEL_DEFAULT`.
487487

488488
.. attribute:: window_log
489489

490490
Maximum allowed back-reference distance the compressor can use when
491-
compressing data, expressed as power of 2, ``1 << window_log`` bytes. This
491+
compressing data, expressed as power of two, ``1 << window_log`` bytes. This
492492
parameter greatly influences the memory usage of compression. Higher
493493
values require more memory but gain better compression values.
494494

495495
.. attribute:: hash_log
496496

497-
Size of the initial probe table, as a power of 2. The resulting memory
497+
Size of the initial probe table, as a power of two. The resulting memory
498498
usage is ``1 << (hash_log+2)`` bytes. Larger tables improve compression
499499
ratio of strategies <= :attr:`~Strategy.dfast`, and improve compression
500500
speed of strategies > :attr:`~Strategy.dfast`.
501501

502502
.. attribute:: chain_log
503503

504-
Size of the multi-probe search table, as a power of 2. The resulting
504+
Size of the multi-probe search table, as a power of two. The resulting
505505
memory usage is ``1 << (chain_log+2)`` bytes. Larger tables result in
506506
better and slower compression. This parameter has no effect for the
507507
:attr:`~Strategy.fast` strategy. It's still useful when using
@@ -510,7 +510,7 @@ Advanced parameter control
510510

511511
.. attribute:: search_log
512512

513-
Number of search attempts, as a power of 2. More attempts result in
513+
Number of search attempts, as a power of two. More attempts result in
514514
better and slower compression. This parameter is useless for
515515
:attr:`~Strategy.fast` and :attr:`~Strategy.dfast` strategies.
516516

@@ -553,12 +553,12 @@ Advanced parameter control
553553
Enabling this parameter increases default
554554
:attr:`~CompressionParameter.window_log` to 128 MiB except when expressly
555555
set to a different value. This setting is enabled by default if
556-
:attr:`~CompressionParameter.window_log` >= 128 MiB and the compression
556+
:attr:`!window_log` >= 128 MiB and the compression
557557
strategy >= :attr:`~Strategy.btopt` (compression level 16+).
558558

559559
.. attribute:: ldm_hash_log
560560

561-
Size of the table for long distance matching, as a power of 2. Larger
561+
Size of the table for long distance matching, as a power of two. Larger
562562
values increase memory usage and compression ratio, but decrease
563563
compression speed.
564564

@@ -586,7 +586,7 @@ Advanced parameter control
586586

587587
.. attribute:: checksum_flag
588588

589-
A 4-byte checksum using XXHash64 of the uncompressed content is written
589+
A four-byte checksum using XXHash64 of the uncompressed content is written
590590
at the end of each frame. Zstandard's decompression code verifies the
591591
checksum. If there is a mismatch a :class:`ZstdError` exception is
592592
raised.
@@ -690,8 +690,7 @@ Miscellaneous
690690

691691
.. class:: FrameInfo
692692

693-
Metadata related to a Zstandard frame. There are currently two attributes
694-
containing metadata related to Zstandard frames.
693+
Metadata related to a Zstandard frame.
695694

696695
.. attribute:: decompressed_size
697696

@@ -707,7 +706,7 @@ Miscellaneous
707706

708707
.. attribute:: COMPRESSION_LEVEL_DEFAULT
709708

710-
The default compression level for Zstandard, currently '3'.
709+
The default compression level for Zstandard: ``3``.
711710

712711

713712
.. attribute:: zstd_version_info
@@ -724,6 +723,7 @@ Reading in a compressed file:
724723
.. code-block:: python
725724
726725
from compression import zstd
726+
727727
with zstd.open("file.zst") as f:
728728
file_content = f.read()
729729
@@ -732,6 +732,7 @@ Creating a compressed file:
732732
.. code-block:: python
733733
734734
from compression import zstd
735+
735736
data = b"Insert Data Here"
736737
with zstd.open("file.zst", "w") as f:
737738
f.write(data)
@@ -741,6 +742,7 @@ Compressing data in memory:
741742
.. code-block:: python
742743
743744
from compression import zstd
745+
744746
data_in = b"Insert Data Here"
745747
data_out = zstd.compress(data_in)
746748
@@ -749,6 +751,7 @@ Incremental compression:
749751
.. code-block:: python
750752
751753
from compression import zstd
754+
752755
comp = zstd.ZstdCompressor()
753756
out1 = comp.compress(b"Some data\n")
754757
out2 = comp.compress(b"Another piece of data\n")
@@ -762,6 +765,7 @@ Writing compressed data to an already-open file:
762765
.. code-block:: python
763766
764767
from compression import zstd
768+
765769
with open("file.zst", "wb") as f:
766770
f.write(b"This data will not be compressed\n")
767771
with zstd.open(f, "w") as zstf:
@@ -773,6 +777,7 @@ Creating a compressed file using compression parameters:
773777
.. code-block:: python
774778
775779
from compression import zstd
780+
776781
options = {
777782
zstd.CompressionParameter.checksum_flag: 1
778783
}

0 commit comments

Comments
 (0)