Skip to content
Prev Previous commit
Next Next commit
Update documentation for zlib
  • Loading branch information
rhpvorderman committed Mar 24, 2021
commit ff24df370f9b78140078672401e421b7c438d496
48 changes: 29 additions & 19 deletions Doc/library/zlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,43 @@ The available exception and functions in this module are:
platforms, use ``adler32(data) & 0xffffffff``.


.. function:: compress(data, /, level=-1)
.. function:: compress(data, /, level=-1, wbits=MAX_WBITS)

Compresses the bytes in *data*, returning a bytes object containing compressed data.
*level* is an integer from ``0`` to ``9`` or ``-1`` controlling the level of compression;

Comment thread
rhpvorderman marked this conversation as resolved.
Outdated
*level* is an integer from ``0`` to ``9`` or ``-1`` controlling the level of compression;
``1`` (Z_BEST_SPEED) is fastest and produces the least compression, ``9`` (Z_BEST_COMPRESSION)
is slowest and produces the most. ``0`` (Z_NO_COMPRESSION) is no compression.
The default value is ``-1`` (Z_DEFAULT_COMPRESSION). Z_DEFAULT_COMPRESSION represents a default
compromise between speed and compression (currently equivalent to level 6).

.. _compress-wbits:

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

* +9 to +15: The base-two logarithm of the window size, which
therefore ranges between 512 and 32768. Larger values produce
better compression at the expense of greater memory usage. The
resulting output will include a zlib-specific header and trailer.

* −9 to −15: Uses the absolute value of *wbits* as the
window size logarithm, while producing a raw output stream with no
header or trailing checksum.

* +25 to +31 = 16 + (9 to 15): Uses the low 4 bits of the value as the
window size logarithm, while including a basic :program:`gzip` header
and trailing checksum in the output.

Raises the :exc:`error` exception if any error occurs.

.. versionchanged:: 3.6
*level* can now be used as a keyword parameter.

.. versionchanged:: 3.10
Comment thread
rhpvorderman marked this conversation as resolved.
Outdated
*wbits* parameter added.
Comment thread
rhpvorderman marked this conversation as resolved.
Outdated

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

Expand All @@ -76,23 +100,9 @@ The available exception and functions in this module are:
*method* is the compression algorithm. Currently, the only supported value is
:const:`DEFLATED`.

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

* +9 to +15: The base-two logarithm of the window size, which
therefore ranges between 512 and 32768. Larger values produce
better compression at the expense of greater memory usage. The
resulting output will include a zlib-specific header and trailer.

* −9 to −15: Uses the absolute value of *wbits* as the
window size logarithm, while producing a raw output stream with no
header or trailing checksum.

* +25 to +31 = 16 + (9 to 15): Uses the low 4 bits of the value as the
window size logarithm, while including a basic :program:`gzip` header
and trailing checksum in the output.
The *wbits* parameter controls the size of the history buffer (or the
"window size"), and what header and trailer format will be used It has
Comment thread
rhpvorderman marked this conversation as resolved.
Outdated
the same meaning as `described for compress() <#compress-wbits>`__.

The *memLevel* argument controls the amount of memory used for the
internal compression state. Valid values range from ``1`` to ``9``.
Expand Down