<font face="Courier, Monospaced">I'm writing a program in python that creates tar files of a certain <br> maximum size (to fit onto CD/DVD). &nbsp;One of the problems I'm running <br> into is that when using compression, it's pretty much impossible to 
<br> determine if a file, once added to an archive, will cause the archive <br> size to exceed the maximum size. <br> </font><p><font face="Courier, Monospaced">I believe that to do this properly, you need to copy the state of tar 
<br> file (basically the current file offset as well as the state of the <br> compression object), then add the file. &nbsp;If the new size of the archive <br> exceeds the maximum, you need to restore the original state. <br>
 
</font></p><p><font face="Courier, Monospaced">The critical part is being able to copy the compression object. <br> Without compression it is trivial to determine if a given file will <br> &quot;fit&quot; inside the archive. &nbsp;When using compression, the compression 
<br> ratio of a file depends partially on all the data that has been <br> compressed prior to it. <br> </font></p><p><font face="Courier, Monospaced">The current implementation in the standard library does not allow you 
<br> to copy these compression objects in a useful way, so I've made some <br> minor modifications (patch attached) to the standard 2.4.2 library: <br>  - Add copy() method to zlib compression object. &nbsp;This returns a new 
<br> compression object with the same internal state. &nbsp;I named it copy() to <br>  keep it consistent with things like sha.copy(). <br>  - Add snapshot() / restore() methods to GzipFile and TarFile. &nbsp;These <br> work only in write mode. &nbsp;snapshot() returns a state object. &nbsp;Passing 
<br> in this state object to restore() will restore the state of the <br>  GzipFile / TarFile to the state represented by the object. <br> </font></p><p><font face="Courier, Monospaced">Future work: <br>
 - Decompression objects could use a copy() method too <br> - Add support for copying bzip2 compression objects <br> </font></p><p><font face="Courier, Monospaced">Although this patch isn't complete, does this seem like a good approach? 
<br> </font></p><p><font face="Courier, Monospaced">Cheers, <br> Chris <br> </font></p>