I'm trying to uncompress a *.Z file using Python. I downloaded it via FTP (binary mode). The file successfully uncompresses with 7zip (whose "info" on the file says it's of type "Z"). The original file can be found at ftp://cddis.gsfc.nasa.gov/gps/products/1860/igr18600.sp3.Z.
I've read up on the use of the zlib module in Python and have some test code I'm using:
import zlib
comp_data = open('C:Tempigr18600.sp3.Z', 'rb').read()
print(comp_data[0:10])
uncomp_data = zlib.decompress(comp_data)
with open('c:empigr18600.sp3', 'wb') as f:
f.write(uncomp_data)
f.close()
When I execute this I get the following output:
b'x1fx9dx90#xc6@x91x01#F'
Traceback (most recent call last):
File "test.py", line 7, in <module>
uncomp_data = zlib.decompress(comp_data)
zlib.error: Error -3 while decompressing data: incorrect header check
zlib clearly doesn't like the header. The first couple of bytes appear to match the proper magic number sequence 0x1F9d for a compressed file (per https://en.wikipedia.org/wiki/List_of_file_signatures).
In a pinch I can work around this by shelling out to 7zip directly. But I was hoping to find a pure Python type of answer. Despite spending most of the day googling for an answer (or this error message) I haven't had much luck. Perhaps my search skills are atrophying?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…