mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
gh-116931: Add fileobj parameter check for Tarfile.addfile (GH-117988)
Tarfile.addfile now throws an ValueError when the user passes in a non-zero size tarinfo but does not provide a fileobj, instead of writing an incomplete entry.
This commit is contained in:
parent
3e7d990a09
commit
15b3555e4a
4 changed files with 25 additions and 9 deletions
|
|
@ -637,11 +637,15 @@ 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
|
||||
Add the :class:`TarInfo` object *tarinfo* to the archive. If *tarinfo* represents
|
||||
a non zero-size regular file, the *fileobj* argument 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 directly, or by using :meth:`gettarinfo`.
|
||||
|
||||
.. versionchanged:: 3.13
|
||||
|
||||
*fileobj* must be given for non-zero-sized regular files.
|
||||
|
||||
|
||||
.. method:: TarFile.gettarinfo(name=None, arcname=None, fileobj=None)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue