[Tutor] getting the size of an open TarFile object
Adam A. Zajac
strider1551 at gmail.com
Sun Aug 19 05:44:06 CEST 2007
I've been working with the tarfile module and just noticed an apparent
flaw in my own logic. I wanted to add files to the tar until it neared
a certain file size. After every addition I would use
os.path.getsize(). What I noticed today is that I could add a file to
the tar without the tar's size changing. I'm assuming that because the
TarFile object is not closed, finding its size that way isn't reliable.
The first thing I tried was using flush(), but TarFile objects
apparently don't do that. I also can't close the object and reopen it
for appending because TarFile objects can't append if the tar is
compressed. And finally, I can't predict the compression ratio, so I
can't merely keep track of the size of the individual files without a
huge gap to my target size.
I'm giving up on it for the night. Anyone have any thoughts?
More information about the Tutor