Lars Gustäbel added the comment:

tarfile needs to know the size of a file object beforehand because the tar 
header is written first followed by the file object's data. If the file object 
is not based on a real file descriptor, tarfile cannot simply use os.fstat() 
but the user has to pass the size somehow. And I doubt that it's a good idea to 
add size arguments to TarFile.add() and .addfile() because it might lead to 
confusion.

I think tarfile is rather good at exposing the important parts of its low-level 
api to the programmer, in a way that still leaves some work for him to do but 
without getting in his way.  I don't see why manually creating TarInfo objects 
is such a big deal. It is the far superior way because it offers the maximum 
freedom for the programmer - admittedly at the cost of a slightly steeper 
learning curve. And we have to account for many different use cases that people 
have. For example, you don't mention what you think creating directories from 
scratch should be like in your opinion.

With regard to the usage of the size attribute the documentation for 
TarFile.addfile() says clearly:

"""Add the 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 
TarInfo objects using gettarinfo()."""

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22208>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to