0

Possible Duplicate:
uncompressing tar.Z file with python?

I am trying to read a zlib compressed in order to directly access the data in the contained HDF file (using pyhdf). However, I always receive an error message. Here is the file.

import zlib
file = open('3B42.20070101.00.7A.HDF.Z','rb')
data = zlib.decompress(file.read())

>> error: Error -3 while decompressing data: incorrect header check

I checked several other ways (e.g. gzip.open/gzip.zlib) but nothing seems to work. Do you have any suggestions?

Community
  • 1
  • 1
HyperCube
  • 3,870
  • 9
  • 41
  • 53

1 Answers1

3

That's not a zlib or gzip file, it's compressed by the old Unix tool compress (as you can tell from the .Z extension). The command-line tools gzip/gunzip/zcat can read those, but not the Python gzip module. You could use a pipe:

from subprocess import Popen, PIPE

filename = "3B42.20070101.03.7A.HDF.Z"
f = Popen(["zcat", filename], stdout=PIPE).stdout

Now, f is a file-like that can be used to read the file.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836