Commit bd1712a4 authored by pm22d12's avatar pm22d12
Browse files

Fixed an error in decompressing .Z files

parent 2173d4ed
......@@ -357,15 +357,15 @@ class File(object):
else:
# create a explicite new file name for the uncompressed file
unzipFile = File(self.getName() + ".un" + ct + "ed")
# Open the current compressed file
self.open("r")
# Open the new uncompressed file
if comptype == File.ZIP:
# Open the current compressed file
self.open("r")
filenames = self.__fd.namelist()
if len(filenames) > 1:
raise Exception("ZipFile must only contains one file")
# Open the new uncompressed file
_filepath, name = os.path.split(filenames[0])
unzipFile = File(os.path.join(self.__path, name))
unzipFile.open("wb")
......@@ -377,31 +377,36 @@ class File(object):
self.close()
unzipFile.close()
raise
elif comptype == File.LZW:
data_uncompress = True
unzipFile.open("wb")
try:
data = self.__fd.read()
data_uncompress = unlzw(data)
unzipFile.write(data_uncompress)
except:
self.close()
unzipFile.close()
raise
else:
unzipFile.open("wb")
# do the uncompression copy (with bufferization)
buff = True
try:
while buff:
buff = self.read(READ_BUFFER)
if buff:
unzipFile.write(buff)
except:
# Close the two files
self.close()
unzipFile.close()
raise
# Open the current compressed file
self.open("rb")
if comptype == File.LZW:
data_uncompress = True
# Open the new uncompressed file
unzipFile.open("wb")
try:
data = self.__fd.read()
data_uncompress = unlzw(data)
unzipFile.write(data_uncompress)
except:
self.close()
unzipFile.close()
raise
else:
# Open the new uncompressed file
unzipFile.open("wb")
# do the uncompression copy (with bufferization)
buff = True
try:
while buff:
buff = self.read(READ_BUFFER)
if buff:
unzipFile.write(buff)
except:
# Close the two files
self.close()
unzipFile.close()
raise
# Close the two files
self.close()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment