-
-
Save prostoalex/8763862 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def gzip_string(s, level=6): | |
| """Compress string using gzip. | |
| Default compression level is 6. | |
| """ | |
| zbuf = StringIO() | |
| zfile = GzipFile(mode='wb', compresslevel=level, fileobj=zbuf) | |
| zfile.write(s) | |
| zfile.close() | |
| return zbuf.getvalue() | |
| def gunzip_string(s): | |
| """Decompress string using gzip. | |
| See http://stackoverflow.com/questions/2695152/in-python-how-do-i-decode-gzip-encoding/2695466#2695466 | |
| """ | |
| return zlib.decompress(s, 16 + zlib.MAX_WBITS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment