creating size-limited tar files

Roy Smith roy at panix.com
Wed Nov 7 15:32:23 EST 2012


In article <509ab0fa$0$6636$9b4e6d93 at newsspool2.arcor-online.net>,
 Alexander Blinne <news at blinne.net> wrote:

> I don't know the best way to find the current size, I only have a
> general remark.
> This solution is not so good if you have to impose a hard limit on the
> resulting file size. You could end up having a tar file of size "limit +
> size of biggest file - 1 + overhead" in the worst case if the tar is at
> limit - 1 and the next file is the biggest file. Of course that may be
> acceptable in many cases or it may be acceptable to do something about
> it by adjusting the limit.

If you truly have a hard limit, one possible solution would be to use 
tell() to checkpoint the growing archive after each addition.  If adding 
a new file unexpectedly causes you exceed your hard limit, you can 
seek() back to the previous spot and truncate the file there.

Whether this is worth the effort is an exercise left for the reader.



More information about the Python-list mailing list