2

I am trying to decompress a string that is Gzipped. But I am unable to do so.

string = 'H4sIAAAAAAAAClWPwcrCQAyEX2WOCtJ3+EXw5E3wvLZjG4gb2WR/tU/vFlEQQiATvszkRO3tSoThUDWkhmiH4ySOVjEtG1PcJxbiaRV9ymjErdB9EQqCj4AVDPzVPxMH/CetRHXJI/az3FbjvN5gx0vS4MJui4XKFxHLSDpakZiu3uFP3X7cU0uzhHOZiTPjTua3q7fWEykPaJfaS5CM8zPo3QvUlCS87AAAAA=='
x = gzip.decompress(string).decode()

But this throws an error. But the string should be decompressed to "Welcome to Multiutil. This is the tool where you can compress your text or decompress your compressed value using Gzip(gz), Defalte or Brotli compression algorithms. Also you can compare the size between your source and result in bytes." Is there a way to decompress the string in Python?

potterson11
  • 147
  • 7

1 Answers1

3

First decode the base64 encoded string.

import base64
import gzip

binary_string = base64.b64decode(string)
x = gzip.decompress(binary_string).decode()

Welcome to Multiutil. This is the tool where you can compress your text or decompress your compressed value using Gzip(gz), Defalte or Brotli compression algorithms. Also you can compare the size between your source and result in bytes.
Jamiu S.
  • 5,257
  • 5
  • 12
  • 34