diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-02-19 23:34:56 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-02-19 23:34:56 (GMT) |
commit | 59b9a16e72757e1b6266b251f8b12dd9bf69d603 (patch) | |
tree | 937957b4bdbaffec5e8c54fe0a2ed26dcf750ac0 /Doc | |
parent | d6dd0e65601355bfff52c85b3ac7800ed7edffb5 (diff) | |
download | cpython-59b9a16e72757e1b6266b251f8b12dd9bf69d603.zip cpython-59b9a16e72757e1b6266b251f8b12dd9bf69d603.tar.gz cpython-59b9a16e72757e1b6266b251f8b12dd9bf69d603.tar.bz2 |
Issues #22468, #21996, #22208: Clarify gettarinfo() and TarInfo usage
* Make it more obvious gettarinfo() is based on stat(), and that non-ordinary
files may need special care
* Filename taken from fileobj.name; suggest dummy arcname as a workaround
* Indicate TarInfo may be used directly, not just via gettarinfo()
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/tarfile.rst | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst index 2135db4..019c685 100644 --- a/Doc/library/tarfile.rst +++ b/Doc/library/tarfile.rst @@ -438,20 +438,29 @@ be finalized; only the internally used file object will be closed. See the Add the :class:`TarInfo` object *tarinfo* to the archive. If *fileobj* is given, ``tarinfo.size`` bytes are read from it and added to the archive. You can - create :class:`TarInfo` objects using :meth:`gettarinfo`. + create :class:`TarInfo` objects directly, or by using :meth:`gettarinfo`. .. note:: - On Windows platforms, *fileobj* should always be opened with mode ``'rb'`` to avoid irritation about the file size. .. method:: TarFile.gettarinfo(name=None, arcname=None, fileobj=None) - Create a :class:`TarInfo` object for either the file *name* or the 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 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:`~file.name` attribute, or the *name* argument. + + 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() |