Add a tbz2.get_data() method that returns the xpak segment data as a dict.
authorZac Medico <zmedico@gentoo.org>
Sun, 19 Feb 2006 23:28:14 +0000 (23:28 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 19 Feb 2006 23:28:14 +0000 (23:28 -0000)
svn path=/main/trunk/; revision=2751

pym/xpak.py

index 9e918801c4af33c56944b568477b966b3d055ef8..c5c487e0a5f9cbb1131ea7accad5b1a03f551e50 100644 (file)
@@ -389,6 +389,24 @@ class tbz2:
                os.chdir(origdir)
                return 1
 
+       def get_data(self):
+               """Returns all the files from the dataSegment as a map object."""
+               if not self.scan():
+                       return 0
+               a = open(self.file, "r")
+               mydata = {}
+               startpos=0
+               while ((startpos+8)<self.indexsize):
+                       namelen=decodeint(self.index[startpos:startpos+4])
+                       datapos=decodeint(self.index[startpos+4+namelen:startpos+8+namelen]);
+                       datalen=decodeint(self.index[startpos+8+namelen:startpos+12+namelen]);
+                       myname=self.index[startpos+4:startpos+4+namelen]
+                       a.seek(self.datapos+datapos)
+                       mydata[myname] = a.read(datalen)
+                       startpos=startpos+namelen+12
+               a.close()
+               return mydata
+
        def getboth(self):
                """Returns an array [indexSegment,dataSegment]"""
                if not self.scan():