Python decompress gzip data in memory without file
问题 I have gzipped data from HTTP reply. I have following code: def gzipDecode(self, content): import StringIO import gzip outFilePath = 'test' compressedFile = StringIO.StringIO(content) decompressedFile = gzip.GzipFile(fileobj=compressedFile) with open(outFilePath, 'w') as outfile: outfile.write(decompressedFile.read()) data = '' with open(outFilePath, 'r') as myfile: data=myfile.read().replace('\n', '') return data which decompress input gzipped content and return string (http reply is gzipped