Skip to content

gh-91349: Adjust default compression level to 6 (down from 9) in gzip and tarfile #131470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -184,7 +184,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
Expand Down
4 changes: 2 additions & 2 deletions Lib/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,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 Expand Up @@ -1944,7 +1944,7 @@ def gzopen(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs):
return t

@classmethod
def bz2open(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs):
def bz2open(cls, name, mode="r", fileobj=None, compresslevel=6, **kwargs):
"""Open bzip2 compressed tar archive name for reading or writing.
Appending is not allowed.
"""
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.
It is the default level used by most compression tools and a better
tradeoff between speed and performance.
Loading