mylist.sort()
mydata = {}
for x in mylist:
- a = open(x, "r")
+ a = open(x, 'rb')
mydata[x] = a.read()
a.close()
os.chdir(origdir)
xpak_segment = xpak_mem(mydata)
if outfile:
- outf = open(outfile, "w")
+ outf = open(outfile, 'wb')
outf.write(xpak_segment)
outf.close()
else:
"""(infile) -- Splits the infile into two files.
'infile.index' contains the index segment.
'infile.dat' contails the data segment."""
- myfile=open(infile,"r")
+ myfile = open(infile, 'rb')
mydat=myfile.read()
myfile.close()
if not splits:
return False
- myfile=open(infile+".index","w")
+ myfile = open(infile + '.index', 'wb')
myfile.write(splits[0])
myfile.close()
- myfile=open(infile+".dat","w")
+ myfile = open(infile + '.dat', 'wb')
myfile.write(splits[1])
myfile.close()
return True
def getindex(infile):
"""(infile) -- grabs the index segment from the infile and returns it."""
- myfile=open(infile,"r")
+ myfile = open(infile, 'rb')
myheader=myfile.read(16)
if myheader[0:8]!="XPAKPACK":
myfile.close()
def getboth(infile):
"""(infile) -- grabs the index and data segments from the infile.
Returns an array [indexSegment,dataSegment]"""
- myfile=open(infile,"r")
+ myfile = open(infile, 'rb')
myheader=myfile.read(16)
if myheader[0:8]!="XPAKPACK":
myfile.close()
if dirname:
if not os.path.exists(dirname):
os.makedirs(dirname)
- mydat=open(myname,"w")
+ mydat = open(myname, 'wb')
mydat.write(mydata[datapos:datapos+datalen])
mydat.close()
startpos=startpos+namelen+12
def recompose_mem(self, xpdata):
self.scan() # Don't care about condition... We'll rewrite the data anyway.
- myfile=open(self.file,"a+")
+ myfile = open(self.file, 'ab+')
if not myfile:
raise IOError
myfile.seek(-self.xpaksize,2) # 0,2 or -0,2 just mean EOF.
if not changed:
return 1
self.filestat=mystat
- a=open(self.file,"r")
+ a = open(self.file, 'rb')
a.seek(-16,2)
trailer=a.read()
self.infosize=0
myresult=searchindex(self.index,myfile)
if not myresult:
return mydefault
- a=open(self.file,"r")
+ a = open(self.file, 'rb')
a.seek(self.datapos+myresult[0],0)
myreturn=a.read(myresult[1])
a.close()
except:
os.chdir("/")
origdir="/"
- a=open(self.file,"r")
+ a = open(self.file, 'rb')
if not os.path.exists(mydest):
os.makedirs(mydest)
os.chdir(mydest)
if dirname:
if not os.path.exists(dirname):
os.makedirs(dirname)
- mydat=open(myname,"w")
+ mydat = open(myname, 'wb')
a.seek(self.datapos+datapos)
mydat.write(a.read(datalen))
mydat.close()
"""Returns all the files from the dataSegment as a map object."""
if not self.scan():
return 0
- a = open(self.file, "r")
+ a = open(self.file, 'rb')
mydata = {}
startpos=0
while ((startpos+8)<self.indexsize):
if not self.scan():
return None
- a = open(self.file,"r")
+ a = open(self.file, 'rb')
a.seek(self.datapos)
mydata =a.read(self.datasize)
a.close()