Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gzip
- import base64
- import StringIO
- # python bgzip.py
- # H4sIAErhF1wC/8tIzcnJBwCGphA2BQAAAA==
- # hello
- def gzip_and_base64(s):
- out = StringIO.StringIO()
- with gzip.GzipFile(fileobj=out, mode='w') as fh:
- fh.write(s)
- # return gzipped string base64 encoded
- return base64.b64encode(out.getvalue())
- def base64_and_gunzip(s):
- decoded = base64.b64decode(s)
- fo = StringIO.StringIO(decoded)
- return gzip.GzipFile(fileobj=fo).read()
- zipped = gzip_and_base64('hello')
- print(zipped)
- unzipped = base64_and_gunzip(zipped)
- print(unzipped)
Add Comment
Please, Sign In to add comment