Trying to decode gzip compressed and base64 encoded data to a readable format in Python3.4.
import base64
import zlib
original_data = '...jU2X0NCQ19TSEEAAAABAAA=' #Data cut short.
decoded64 = base64.b64decode(original_data) #format:b'\x16xe\x94...\xae\x9a\...'
final_decoded = zlib.decompress(decoded64)
print(final_decoded)
Been getting: "Error -2 while preparing to decompress data: inconsistent stream state." Not sure what I'm doing wrong.
zlib
successfully decompresses data that it has compressed previously:zlib
fails to decompress (with the default settings)gzip
data:I had the same problem and solve it this way:
Using this your code doesn't write a file, I tested. Is very useful because you can easily read a file inside a zip file, previously received by rest for example.