Extracting bzip2 & gzip files
Jaco Greeff
jaco at puxedo.org
Tue Feb 12 12:26:18 EST 2002
Hi,
I have a function to read compressed and uncompressed files into a string.
Unfortionately, I need some help in getting the thing to actually work. As
you can see from the function below, I'm using system calls to read the file
into a string and then return it, but am receivcing errors from the actual
bzip2 execution:
"It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.
You can use the `bzip2recover' program to *attempt* to recover
data from undamaged sections of corrupted files."
I'm stumped. If I could get it to work for bzip2 only, I'll
be happy - I have looked at the pybz2 0.02 module, but it seems to not want
to compile on my system, hence my "workaround":
def readFile(file, comp='None'):
if comp == 'bz2':
r, s = commands.getstatusoutput(string.join(['bzcat', file], ' '))
elif comp == 'gz':
r, s = commands.getstatusoutput(string.join(['gunzip -c', file], ' '))
else:
r, s = commands.getstatusoutput(string.join(['cat', file], ' '))
r == 1:
print 'Error:', s
s = ''
return s
Any ideas? Help on this?
Thanks and greetings,
Jaco
More information about the Python-list
mailing list