Visitar URL original
gh-91349: Adjust default compression level to 6 (down from 9) in gzip and tarfile by morotti · Pull Request #131470 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Doc/library/gzip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Note that additional file formats which can be decompressed by the
The module defines the following items:


.. function:: open(filename, mode='rb', compresslevel=9, encoding=None, errors=None, newline=None)
.. function:: open(filename, mode='rb', compresslevel=6, encoding=None, errors=None, newline=None)

Open a gzip-compressed file in binary or text mode, returning a :term:`file
object`.
Expand Down Expand Up @@ -67,7 +67,7 @@ The module defines the following items:

.. versionadded:: 3.8

.. class:: GzipFile(filename=None, mode=None, compresslevel=9, fileobj=None, mtime=None)
.. class:: GzipFile(filename=None, mode=None, compresslevel=6, fileobj=None, mtime=None)

Constructor for the :class:`GzipFile` class, which simulates most of the
methods of a :term:`file object`, with the exception of the :meth:`~io.IOBase.truncate`
Expand Down Expand Up @@ -182,7 +182,7 @@ The module defines the following items:
attribute instead.


.. function:: compress(data, compresslevel=9, *, mtime=0)
.. function:: compress(data, compresslevel=6, *, mtime=0)

Compress the *data*, returning a :class:`bytes` object containing
the compressed data. *compresslevel* and *mtime* have the same meaning as in
Comment thread
morotti marked this conversation as resolved.
Expand Down
6 changes: 3 additions & 3 deletions Lib/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
_WRITE_BUFFER_SIZE = 4 * io.DEFAULT_BUFFER_SIZE


def open(filename, mode="rb", compresslevel=_COMPRESS_LEVEL_BEST,
def open(filename, mode="rb", compresslevel=_COMPRESS_LEVEL_TRADEOFF,
encoding=None, errors=None, newline=None):
"""Open a gzip-compressed file in binary or text mode.

Expand Down Expand Up @@ -158,7 +158,7 @@ class GzipFile(_streams.BaseStream):
myfileobj = None

def __init__(self, filename=None, mode=None,
compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
compresslevel=_COMPRESS_LEVEL_TRADEOFF, fileobj=None, mtime=None):
"""Constructor for the GzipFile class.

At least one of fileobj and filename must be given a
Expand Down Expand Up @@ -621,7 +621,7 @@ def _rewind(self):
self._new_member = True


def compress(data, compresslevel=_COMPRESS_LEVEL_BEST, *, mtime=0):
def compress(data, compresslevel=_COMPRESS_LEVEL_TRADEOFF, *, mtime=0):
"""Compress data in one shot and return the compressed string.

compresslevel sets the compression level in range of 0-9.
Expand Down
2 changes: 1 addition & 1 deletion Lib/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ def taropen(cls, name, mode="r", fileobj=None, **kwargs):
return cls(name, mode, fileobj, **kwargs)

@classmethod
def gzopen(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs):
def gzopen(cls, name, mode="r", fileobj=None, compresslevel=6, **kwargs):
"""Open gzip compressed tar archive name for reading or writing.
Appending is not allowed.
"""
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def test_mtime(self):
def test_metadata(self):
mtime = 123456789

with gzip.GzipFile(self.filename, 'w', mtime = mtime) as fWrite:
with gzip.GzipFile(self.filename, 'w', mtime = mtime, compresslevel = 9) as fWrite:
fWrite.write(data1)

with open(self.filename, 'rb') as fRead:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Adjust default compression level to 6 (down from 9) in gzip and tarfile.
Comment thread
morotti marked this conversation as resolved.
Outdated
Comment thread
morotti marked this conversation as resolved.
Outdated
It is the default level used by most compression tools and a better
tradeoff between speed and performance.