@@ -69,9 +69,22 @@ The available exception and functions in this module are:
6969 *method * is the compression algorithm. Currently, the only supported value is
7070 ``DEFLATED ``.
7171
72- *wbits * is the base two logarithm of the size of the window buffer. This
73- should be an integer from ``8 `` to ``15 ``. Higher values give better
74- compression, but use more memory.
72+ The *wbits * argument controls the size of the history buffer (or the
73+ "window size") used when compressing data, and whether a header and
74+ trailer is included in the output. It can take several ranges of values:
75+
76+ * +9 to +15: The base-two logarithm of the window size, which
77+ therefore ranges between 512 and 32768. Larger values produce
78+ better compression at the expense of greater memory usage. The
79+ resulting output will include a zlib-specific header and trailer.
80+
81+ * −9 to −15: Uses the absolute value of *wbits * as the
82+ window size logarithm, while producing a raw output stream with no
83+ header or trailing checksum.
84+
85+ * +25 to +31 = 16 + (9 to 15): Uses the low 4 bits of the value as the
86+ window size logarithm, while including a basic :program: `gzip ` header
87+ and trailing checksum in the output.
7588
7689 The *memLevel * argument controls the amount of memory used for the
7790 internal compression state. Valid values range from ``1 `` to ``9 ``.
@@ -113,20 +126,39 @@ The available exception and functions in this module are:
113126.. function :: decompress(data[, wbits[, bufsize]])
114127
115128 Decompresses the bytes in *data *, returning a bytes object containing the
116- uncompressed data. The *wbits * parameter controls the size of the window
117- buffer , and is discussed further below.
129+ uncompressed data. The *wbits * parameter depends on
130+ the format of * data * , and is discussed further below.
118131 If *bufsize * is given, it is used as the initial size of the output
119132 buffer. Raises the :exc: `error ` exception if any error occurs.
120133
121- The absolute value of *wbits * is the base two logarithm of the size of the
122- history buffer (the "window size") used when compressing data. Its absolute
123- value should be between 8 and 15 for the most recent versions of the zlib
124- library, larger values resulting in better compression at the expense of greater
125- memory usage. When decompressing a stream, *wbits * must not be smaller
134+ .. _decompress-wbits :
135+
136+ The *wbits * parameter controls the size of the history buffer
137+ (or "window size"), and what header and trailer format is expected.
138+ It is similar to the parameter for :func: `compressobj `, but accepts
139+ more ranges of values:
140+
141+ * +8 to +15: The base-two logarithm of the window size. The input
142+ must include a zlib header and trailer.
143+
144+ * 0: Automatically determine the window size from the zlib header.
145+
146+ * −8 to −15: Uses the absolute value of *wbits * as the window size
147+ logarithm. The input must be a raw stream with no header or trailer.
148+
149+ * +24 to +31 = 16 + (8 to 15): Uses the low 4 bits of the value as
150+ the window size logarithm. The input must include a gzip header and
151+ trailer.
152+
153+ * +40 to +47 = 32 + (8 to 15): Uses the low 4 bits of the value as
154+ the window size logarithm, and automatically accepts either
155+ the zlib or gzip format.
156+
157+ When decompressing a stream, the window size must not be smaller
126158 than the size originally used to compress the stream; using a too-small
127- value will result in an exception. The default value is therefore the
128- highest value, 15. When * wbits * is negative, the standard
129- :program: ` gzip ` header is suppressed .
159+ value may result in an :exc: ` error ` exception. The default * wbits * value
160+ is 15, which corresponds to the largest window size and requires a zlib
161+ header and trailer to be included .
130162
131163 *bufsize * is the initial size of the buffer used to hold decompressed data. If
132164 more space is required, the buffer size will be increased as needed, so you
@@ -139,7 +171,9 @@ The available exception and functions in this module are:
139171 Returns a decompression object, to be used for decompressing data streams that
140172 won't fit into memory at once.
141173
142- The *wbits * parameter controls the size of the window buffer.
174+ The *wbits * parameter controls the size of the history buffer (or the
175+ "window size"), and what header and trailer format is expected. It has
176+ the same meaning as `described for decompress() <#decompress-wbits >`__.
143177
144178 The *zdict * parameter specifies a predefined compression dictionary. If
145179 provided, this must be the same dictionary as was used by the compressor that
0 commit comments