Skip to content

Commit d7dd20b

Browse files
committed
gh-82907: Document mtime=0 for reproducible tarfile gzip output
tarfile.open() already writes a fixed zero timestamp in the gzip header when mtime=0 is passed, on both the 'w:gz' and 'w|gz' paths, producing output that does not depend on the archive creation time. Document this special value, matching the existing wording in the gzip module docs.
1 parent 7241f27 commit d7dd20b

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

Doc/library/tarfile.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ Some facts and figures:
144144

145145
For modes ``'w:gz'`` and ``'w|gz'``, :func:`tarfile.open` accepts the
146146
keyword argument *mtime* to create a gzip archive header with that mtime. By
147-
default, the mtime is set to the time of creation of the archive.
147+
default, the mtime is set to the time of creation of the archive. Use
148+
*mtime* ``0`` to generate a compressed stream that does not depend on
149+
creation time, for reproducible output.
148150

149151
For special purposes, there is a second format for *mode*:
150152
``'filemode|[compression]'``. :func:`tarfile.open` will return a :class:`TarFile`
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Document that passing ``mtime=0`` to :func:`tarfile.open` produces a
2+
gzip-compressed archive whose output does not depend on creation time, for
3+
reproducible output.

0 commit comments

Comments
 (0)