Skip to content

Commit 4929259

Browse files
committed
gzip: let compress mtime default to 0
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.
1 parent 65f64b1 commit 4929259

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Doc/library/gzip.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ The module defines the following items:
157157
Accepts a :term:`path-like object`.
158158

159159

160-
.. function:: compress(data, compresslevel=9, *, mtime=None)
160+
.. function:: compress(data, compresslevel=9, *, mtime=0)
161161

162162
Compress the *data*, returning a :class:`bytes` object containing
163163
the compressed data. *compresslevel* and *mtime* have the same meaning as in
@@ -166,6 +166,8 @@ The module defines the following items:
166166
.. versionadded:: 3.2
167167
.. versionchanged:: 3.8
168168
Added the *mtime* parameter for reproducible output.
169+
.. versionchanged:: 3.14
170+
The *mtime* parameter now defaults to 0 for reproducible output
169171

170172
.. function:: decompress(data)
171173

Lib/gzip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def _rewind(self):
520520
super()._rewind()
521521
self._new_member = True
522522

523-
def compress(data, compresslevel=_COMPRESS_LEVEL_BEST, *, mtime=None):
523+
def compress(data, compresslevel=_COMPRESS_LEVEL_BEST, *, mtime=0):
524524
"""Compress data in one shot and return the compressed string.
525525
Optional argument is the compression level, in range of 0-9.
526526
"""

0 commit comments

Comments
 (0)