Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python - how to inflate gzipped, base64d string

I'm just wondering how is it possible to inflate/decompress a string of text that is a gzipped compressed string that also hase base64 encoding?

For instance, all the python examples seem to focus on opening a file, whereas I want to work on a gzipped string.

like image 401
Ke. Avatar asked Oct 17 '25 20:10

Ke.


1 Answers

Under python3, other answers didn't help me but I found this:

import base64
import zlib
data = 'H4sIAAAAAAAAAHWPwQqCQBCGX0Xm7EFtK+smZBEUgXoLCdMhFtKV3akI8d0bLYmibvPPN3wz00CJxmQnTO41whwWQRIctmEcB6sQbFC3CjW3XW8kxpOpP+OC22d1Wml1qZkQGtoMsScxaczKN3plG8zlaHIta5KqWsozoTYw3/djzwhpLwivWFGHGpAFe7DL68JlBUk+l7KSN7tCOEJ4M3/qOI49vMHj+zCKdlFqLaU2ZHV2a4Ct/an0/ivdX8oYc1UVX860fQDQiMdxRQEAAA=='

json_str = zlib.decompress(base64.b64decode(data), 16 + zlib.MAX_WBITS).decode('utf-8')

hope this helps

like image 177
davesave Avatar answered Oct 20 '25 11:10

davesave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!