Skip to content

Instantly share code, notes, and snippets.

View chrisbrake's full-sized avatar
🦉
I may be slow to respond.

Chris chrisbrake

🦉
I may be slow to respond.
View GitHub Profile
@chrisbrake
chrisbrake / string_compression_in_memory.py
Last active August 5, 2017 02:20
Compress and extract a string in memory in Python 2 and 3
from gzip import GzipFile
from io import BytesIO
def compress_string(uncompressed_string):
"""
Takes a string object as an argument, compresses it in memory and returns
a compressed string.
Any Non UTF-8 characters will be stripped during this process.
:param uncompressed_string: Regular Sting