diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-02-19 23:46:59 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-02-19 23:46:59 (GMT) |
commit | 2d2d08d2cc2af98219fd105ec75fa58a633d2b75 (patch) | |
tree | 2b9be4c5ca2d404945a35d3d91380e4d32d0ee21 /Doc | |
parent | 7db1d1620982d8ed13363e89a86852bd8a6c8b86 (diff) | |
parent | f817a48d170e2dfb7c7154f12308e291457a2f8a (diff) | |
download | cpython-2d2d08d2cc2af98219fd105ec75fa58a633d2b75.zip cpython-2d2d08d2cc2af98219fd105ec75fa58a633d2b75.tar.gz cpython-2d2d08d2cc2af98219fd105ec75fa58a633d2b75.tar.bz2 |
Issue #22468: Merge gettarinfo() doc from 3.5
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/tarfile.rst | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst index e418d5b..7a233c1 100644 --- a/Doc/library/tarfile.rst +++ b/Doc/library/tarfile.rst @@ -456,21 +456,28 @@ be finalized; only the internally used file object will be closed. See the .. method:: TarFile.addfile(tarinfo, fileobj=None) Add the :class:`TarInfo` object *tarinfo* to the archive. If *fileobj* is given, + it should be a :term:`binary file`, and ``tarinfo.size`` bytes are read from it and added to the archive. You can - create :class:`TarInfo` objects using :meth:`gettarinfo`. - - .. note:: - - On Windows platforms, *fileobj* should always be opened with mode ``'rb'`` to - avoid irritation about the file size. + create :class:`TarInfo` objects directly, or by using :meth:`gettarinfo`. .. method:: TarFile.gettarinfo(name=None, arcname=None, fileobj=None) - Create a :class:`TarInfo` object for either the file *name* or the :term:`file - object` *fileobj* (using :func:`os.fstat` on its file descriptor). You can modify - some of the :class:`TarInfo`'s attributes before you add it using :meth:`addfile`. - If given, *arcname* specifies an alternative name for the file in the archive. + Create a :class:`TarInfo` object from the result of :func:`os.stat` or + equivalent on an existing file. The file is either named by *name*, or + specified as a :term:`file object` *fileobj* with a file descriptor. If + given, *arcname* specifies an alternative name for the file in the + archive, otherwise, the name is taken from *fileobj*’s + :attr:`~io.FileIO.name` attribute, or the *name* argument. The name + should be a text string. + + You can modify + some of the :class:`TarInfo`’s attributes before you add it using :meth:`addfile`. + If the file object is not an ordinary file object positioned at the + beginning of the file, attributes such as :attr:`~TarInfo.size` may need + modifying. This is the case for objects such as :class:`~gzip.GzipFile`. + The :attr:`~TarInfo.name` may also be modified, in which case *arcname* + could be a dummy string. .. method:: TarFile.close() |