[Python-checkins] cpython (3.2): Issue #15677: Document that zlib and gzip accept a compression level of 0 to

nadeem.vawda python-checkins at python.org
Sun Nov 11 14:20:38 CET 2012


http://hg.python.org/cpython/rev/9dde30690f44
changeset:   80386:9dde30690f44
branch:      3.2
parent:      80379:6ebfdfe74c04
user:        Nadeem Vawda <nadeem.vawda at gmail.com>
date:        Sun Nov 11 14:04:14 2012 +0100
summary:
  Issue #15677: Document that zlib and gzip accept a compression level of 0 to mean 'no compression'.

Patch by Brian Brazil.

files:
  Doc/library/gzip.rst |   7 ++++---
  Doc/library/zlib.rst |  15 ++++++++-------
  Lib/gzip.py          |   7 ++++---
  Misc/NEWS            |   3 +++
  Modules/zlibmodule.c |   6 +++---
  5 files changed, 22 insertions(+), 16 deletions(-)


diff --git a/Doc/library/gzip.rst b/Doc/library/gzip.rst
--- a/Doc/library/gzip.rst
+++ b/Doc/library/gzip.rst
@@ -50,9 +50,10 @@
    supported. If you need to read a compressed file in text mode, wrap your
    :class:`GzipFile` with an :class:`io.TextIOWrapper`.
 
-   The *compresslevel* argument is an integer from ``1`` to ``9`` controlling the
-   level of compression; ``1`` is fastest and produces the least compression, and
-   ``9`` is slowest and produces the most compression.  The default is ``9``.
+   The *compresslevel* argument is an integer from ``0`` to ``9`` controlling
+   the level of compression; ``1`` is fastest and produces the least
+   compression, and ``9`` is slowest and produces the most compression. ``0``
+   is no compression. The default is ``9``.
 
    The *mtime* argument is an optional numeric timestamp to be written to
    the stream when compressing.  All :program:`gzip` compressed streams are
diff --git a/Doc/library/zlib.rst b/Doc/library/zlib.rst
--- a/Doc/library/zlib.rst
+++ b/Doc/library/zlib.rst
@@ -51,19 +51,20 @@
 
 .. function:: compress(data[, level])
 
-   Compresses the bytes in *data*, returning a bytes object containing compressed data.
-   *level* is an integer from ``1`` to ``9`` controlling the level of compression;
-   ``1`` is fastest and produces the least compression, ``9`` is slowest and
-   produces the most.  The default value is ``6``.  Raises the :exc:`error`
-   exception if any error occurs.
+   Compresses the bytes in *data*, returning a bytes object containing
+   compressed data.  *level* is an integer from ``0`` to ``9`` controlling the
+   level of compression; ``1`` is fastest and produces the least compression,
+   ``9`` is slowest and produces the most. ``0`` is no compression. The default
+   value is ``6``.  Raises the :exc:`error` exception if any error occurs.
 
 
 .. function:: compressobj([level])
 
    Returns a compression object, to be used for compressing data streams that won't
-   fit into memory at once.  *level* is an integer from ``1`` to ``9`` controlling
+   fit into memory at once.  *level* is an integer from ``0`` to ``9`` controlling
    the level of compression; ``1`` is fastest and produces the least compression,
-   ``9`` is slowest and produces the most.  The default value is ``6``.
+   ``9`` is slowest and produces the most.  ``0`` is no compression.  The default
+   value is ``6``.
 
 
 .. function:: crc32(data[, value])
diff --git a/Lib/gzip.py b/Lib/gzip.py
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -137,9 +137,10 @@
         A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
         'wb', and 'a' and 'ab'.
 
-        The compresslevel argument is an integer from 1 to 9 controlling the
+        The compresslevel argument is an integer from 0 to 9 controlling the
         level of compression; 1 is fastest and produces the least compression,
-        and 9 is slowest and produces the most compression.  The default is 9.
+        and 9 is slowest and produces the most compression. 0 is no compression
+        at all. The default is 9.
 
         The mtime argument is an optional numeric timestamp to be written
         to the stream when compressing.  All gzip compressed streams
@@ -573,7 +574,7 @@
 
 def compress(data, compresslevel=9):
     """Compress data in one shot and return the compressed string.
-    Optional argument is the compression level, in range of 1-9.
+    Optional argument is the compression level, in range of 0-9.
     """
     buf = io.BytesIO()
     with GzipFile(fileobj=buf, mode='wb', compresslevel=compresslevel) as f:
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -714,6 +714,9 @@
 Documentation
 -------------
 
+- Issue #15677: Document that zlib and gzip accept a compression level of 0 to
+  mean 'no compression'. Patch by Brian Brazil.
+
 - Issue #8040: added a version switcher to the documentation.  Patch by
   Yury Selivanov.
 
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -81,7 +81,7 @@
 PyDoc_STRVAR(compressobj__doc__,
 "compressobj([level]) -- Return a compressor object.\n"
 "\n"
-"Optional arg level is the compression level, in 1-9.");
+"Optional arg level is the compression level, in 0-9.");
 
 PyDoc_STRVAR(decompressobj__doc__,
 "decompressobj([wbits]) -- Return a decompressor object.\n"
@@ -115,7 +115,7 @@
 PyDoc_STRVAR(compress__doc__,
 "compress(string[, level]) -- Returned compressed string.\n"
 "\n"
-"Optional arg level is the compression level, in 1-9.");
+"Optional arg level is the compression level, in 0-9.");
 
 static PyObject *
 PyZlib_compress(PyObject *self, PyObject *args)
@@ -1135,7 +1135,7 @@
 "zlib library, which is based on GNU zip.\n"
 "\n"
 "adler32(string[, start]) -- Compute an Adler-32 checksum.\n"
-"compress(string[, level]) -- Compress string, with compression level in 1-9.\n"
+"compress(string[, level]) -- Compress string, with compression level in 0-9.\n"
 "compressobj([level]) -- Return a compressor object.\n"
 "crc32(string[, start]) -- Compute a CRC-32 checksum.\n"
 "decompress(string,[wbits],[bufsize]) -- Decompresses a compressed string.\n"

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list