Skip to content

Commit 091e851

Browse files
zlib.rst: Link to constants and deduplicate text (GH-140115)
* Link to compression setting constants from compression functions * De-duplicate descriptions of the constants Co-authored-by: Victor Stinner <[email protected]>
1 parent ed672f7 commit 091e851

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

Doc/library/zlib.rst

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,20 @@ The available exception and functions in this module are:
5656

5757
.. versionadded:: 3.15
5858

59-
.. function:: compress(data, /, level=-1, wbits=MAX_WBITS)
59+
.. function:: compress(data, /, level=Z_DEFAULT_COMPRESSION, wbits=MAX_WBITS)
6060

6161
Compresses the bytes in *data*, returning a bytes object containing compressed data.
6262
*level* is an integer from ``0`` to ``9`` or ``-1`` controlling the level of compression;
63-
``1`` (Z_BEST_SPEED) is fastest and produces the least compression, ``9`` (Z_BEST_COMPRESSION)
64-
is slowest and produces the most. ``0`` (Z_NO_COMPRESSION) is no compression.
65-
The default value is ``-1`` (Z_DEFAULT_COMPRESSION). Z_DEFAULT_COMPRESSION represents a default
66-
compromise between speed and compression (currently equivalent to level 6).
63+
See :const:`Z_BEST_SPEED` (``1``), :const:`Z_BEST_COMPRESSION` (``9``),
64+
:const:`Z_NO_COMPRESSION` (``0``), and the default,
65+
:const:`Z_DEFAULT_COMPRESSION` (``-1``) for more information about these values.
6766

6867
.. _compress-wbits:
6968

7069
The *wbits* argument controls the size of the history buffer (or the
7170
"window size") used when compressing data, and whether a header and
7271
trailer is included in the output. It can take several ranges of values,
73-
defaulting to ``15`` (MAX_WBITS):
72+
defaulting to ``15`` (:const:`MAX_WBITS`):
7473

7574
* +9 to +15: The base-two logarithm of the window size, which
7675
therefore ranges between 512 and 32768. Larger values produce
@@ -94,17 +93,15 @@ The available exception and functions in this module are:
9493
The *wbits* parameter is now available to set window bits and
9594
compression type.
9695

97-
.. function:: compressobj(level=-1, method=DEFLATED, wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL, strategy=Z_DEFAULT_STRATEGY[, zdict])
96+
.. function:: compressobj(level=Z_DEFAULT_COMPRESSION, method=DEFLATED, wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL, strategy=Z_DEFAULT_STRATEGY[, zdict])
9897

9998
Returns a compression object, to be used for compressing data streams that won't
10099
fit into memory at once.
101100

102101
*level* is the compression level -- an integer from ``0`` to ``9`` or ``-1``.
103-
A value of ``1`` (Z_BEST_SPEED) is fastest and produces the least compression,
104-
while a value of ``9`` (Z_BEST_COMPRESSION) is slowest and produces the most.
105-
``0`` (Z_NO_COMPRESSION) is no compression. The default value is ``-1`` (Z_DEFAULT_COMPRESSION).
106-
Z_DEFAULT_COMPRESSION represents a default compromise between speed and compression
107-
(currently equivalent to level 6).
102+
See :const:`Z_BEST_SPEED` (``1``), :const:`Z_BEST_COMPRESSION` (``9``),
103+
:const:`Z_NO_COMPRESSION` (``0``), and the default,
104+
:const:`Z_DEFAULT_COMPRESSION` (``-1``) for more information about these values.
108105

109106
*method* is the compression algorithm. Currently, the only supported value is
110107
:const:`DEFLATED`.
@@ -119,7 +116,7 @@ The available exception and functions in this module are:
119116

120117
*strategy* is used to tune the compression algorithm. Possible values are
121118
:const:`Z_DEFAULT_STRATEGY`, :const:`Z_FILTERED`, :const:`Z_HUFFMAN_ONLY`,
122-
:const:`Z_RLE` (zlib 1.2.0.1) and :const:`Z_FIXED` (zlib 1.2.2.2).
119+
:const:`Z_RLE` and :const:`Z_FIXED`.
123120

124121
*zdict* is a predefined compression dictionary. This is a sequence of bytes
125122
(such as a :class:`bytes` object) containing subsequences that are expected
@@ -247,7 +244,7 @@ Compression objects support the following methods:
247244
All pending input is processed, and a bytes object containing the remaining compressed
248245
output is returned. *mode* can be selected from the constants
249246
:const:`Z_NO_FLUSH`, :const:`Z_PARTIAL_FLUSH`, :const:`Z_SYNC_FLUSH`,
250-
:const:`Z_FULL_FLUSH`, :const:`Z_BLOCK` (zlib 1.2.3.4), or :const:`Z_FINISH`,
247+
:const:`Z_FULL_FLUSH`, :const:`Z_BLOCK`, or :const:`Z_FINISH`,
251248
defaulting to :const:`Z_FINISH`. Except :const:`Z_FINISH`, all constants
252249
allow compressing further bytestrings of data, while :const:`Z_FINISH` finishes the
253250
compressed stream and prevents compressing any more data. After calling :meth:`flush`
@@ -365,24 +362,25 @@ behavior:
365362

366363
.. data:: Z_NO_COMPRESSION
367364

368-
Compression level ``0``.
365+
Compression level ``0``; no compression.
369366

370367
.. versionadded:: 3.6
371368

372369

373370
.. data:: Z_BEST_SPEED
374371

375-
Compression level ``1``.
372+
Compression level ``1``; fastest and produces the least compression.
376373

377374

378375
.. data:: Z_BEST_COMPRESSION
379376

380-
Compression level ``9``.
377+
Compression level ``9``; slowest and produces the most compression.
381378

382379

383380
.. data:: Z_DEFAULT_COMPRESSION
384381

385-
Default compression level (``-1``).
382+
Default compression level (``-1``); a compromise between speed and
383+
compression. Currently equivalent to compression level ``6``.
386384

387385

388386
.. data:: Z_DEFAULT_STRATEGY

0 commit comments

Comments
 (0)