I have a problem with this code:
file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0) f = gzip.GzipFile(mode='rb', fileobj=file) print f.read()
I do not know why he does not print anything. If I uncomment the file.seek file, an error will occur:
File "/usr/lib/python2.5/gzip.py", line 263, in _read self._read_gzip_header() File "/usr/lib/python2.5/gzip.py", line 162, in _read_gzip_header magic = self.fileobj.read(2) IOError: [Errno 9] Bad file descriptor
Just for information, this version works just fine:
x = open("test.gzip", 'wb') x.write(base64.b64decode(data)) x.close() f = gzip.GzipFile('test.gzip', 'rb') print f.read()
EDIT: for wrb problem. This does not give me an error during initialization. Python 2.5.2.
>>> t = tempfile.TemporaryFile(mode="wrb") >>> t.write("test") >>> t.seek(0) >>> t.read() Traceback (most recent call last): File "<stdin>", line 1, in <module> IOError: [Errno 9] Bad file descriptor
python base64 gzip
Vojta Rylko
source share