Skip to content

Commit

Permalink
gh-125260: gzip: let compress mtime default to 0
Browse files Browse the repository at this point in the history
this follows GNU gzip, which defaults to
store 0 as mtime for compressing stdin, where no file mtime is involved

This makes gzip.compress(str) output deterministic by default
and greatly helps reproducible builds.
  • Loading branch information
bmwiedemann committed Oct 10, 2024
1 parent 01fc3b3 commit eaa7eb7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Doc/library/gzip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ The module defines the following items:
attribute instead.


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

Compress the *data*, returning a :class:`bytes` object containing
the compressed data. *compresslevel* and *mtime* have the same meaning as in
Expand All @@ -203,6 +203,8 @@ The module defines the following items:
.. versionchanged:: 3.13
The gzip header OS byte is guaranteed to be set to 255 when this function
is used as was the case in 3.10 and earlier.
.. versionchanged:: 3.14
The *mtime* parameter now defaults to 0 for reproducible output.

.. function:: decompress(data)

Expand Down
3 changes: 1 addition & 2 deletions Lib/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,7 @@ def _rewind(self):
super()._rewind()
self._new_member = True


def compress(data, compresslevel=_COMPRESS_LEVEL_BEST, *, mtime=None):
def compress(data, compresslevel=_COMPRESS_LEVEL_BEST, *, mtime=0):
"""Compress data in one shot and return the compressed string.
compresslevel sets the compression level in range of 0-9.
Expand Down

0 comments on commit eaa7eb7

Please sign in to comment.