In order do avoid the need for temporary files, add a new tbz2.recompose_mem() method...
authorZac Medico <zmedico@gentoo.org>
Sun, 19 Feb 2006 20:47:44 +0000 (20:47 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 19 Feb 2006 20:47:44 +0000 (20:47 -0000)
svn path=/main/trunk/; revision=2748

pym/xpak.py

index 56c2f4b07a9ca94c4d0470911499e38ec4c9e1a9..9e918801c4af33c56944b568477b966b3d055ef8 100644 (file)
@@ -256,18 +256,21 @@ class tbz2:
                """Creates an xpak segment from the datadir provided, truncates the tbz2
                to the end of regular data if an xpak segment already exists, and adds
                the new segment to the file with terminating info."""
+               xpdata = xpak(datadir)
+               self.recompose_mem(xpdata)
+               if cleanup:
+                       self.cleanup(datadir)
+
+       def recompose_mem(self, xpdata):
                self.scan() # Don't care about condition... We'll rewrite the data anyway.
                myfile=open(self.file,"a+")
                if not myfile:
                        raise IOError
                myfile.seek(-self.xpaksize,2) # 0,2 or -0,2 just mean EOF.
                myfile.truncate()
-               xpdata=xpak(datadir)
                myfile.write(xpdata+encodeint(len(xpdata))+"STOP")
                myfile.flush()
                myfile.close()
-               if cleanup:
-                       self.cleanup(datadir)
                return 1
 
        def cleanup(self, datadir):