From e2d0562d0ca8fc15bb10e71f0f23db29b5698043 Mon Sep 17 00:00:00 2001 From: rmorotti Date: Wed, 19 Mar 2025 12:46:00 +0000 Subject: [PATCH] gh-91349: 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. --- Doc/library/gzip.rst | 6 +++--- Lib/tarfile.py | 4 ++-- .../Library/2025-03-19-12-41-42.gh-issue-91349.8eTOCP.rst | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-03-19-12-41-42.gh-issue-91349.8eTOCP.rst diff --git a/Doc/library/gzip.rst b/Doc/library/gzip.rst index f24e73517e5767..7942918054f6d8 100644 --- a/Doc/library/gzip.rst +++ b/Doc/library/gzip.rst @@ -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`. @@ -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` @@ -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 diff --git a/Lib/tarfile.py b/Lib/tarfile.py index a0fab46b24e249..9829e5fee5c1ad 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -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. """ @@ -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. """ diff --git a/Misc/NEWS.d/next/Library/2025-03-19-12-41-42.gh-issue-91349.8eTOCP.rst b/Misc/NEWS.d/next/Library/2025-03-19-12-41-42.gh-issue-91349.8eTOCP.rst new file mode 100644 index 00000000000000..8739a4b6498630 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-03-19-12-41-42.gh-issue-91349.8eTOCP.rst @@ -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.