Add a file to a compressed tarfile

Eddie Corns eddie at holyrood.ed.ac.uk
Fri Nov 5 11:01:59 EST 2004


Dennis Hotson <djdennie69 at hotmail.com> writes:


>I'm currently trying to read all of the files inside the tarfile... then
>writing them all back. Bit of a kludge, but it should work..

There isn't really any other way.  A tar file is terminated by two empty
blocks.  In order to append to a tar file you simply append a new tar file two
blocks from the end of the original.  If it was uncompressed you just seek
back from the end and write but if it's compressed you can't find that point
without decompressing[1].  In some cases a more time efficient but less space
efficient method would be to just compress individual files in a directory and
then tar them up before the final distribution (or whatever you do with your
tar file)

Eddie

[1] I think, unless there's a clever way of just decompressing the last few
    blocks.



More information about the Python-list mailing list