Skip to content

Instantly share code, notes, and snippets.

View Garrett-R's full-sized avatar
🎯
Focusing

Garrett Reynolds Garrett-R

🎯
Focusing
  • UpCodes
  • San Francisco, CA
View GitHub Profile
@Garrett-R
Garrett-R / gzip_str.py
Last active March 12, 2022 10:17
Demo of how to gzip and gunzip a string in Python 3
"""How to gzip a string.
This works for Python 3.2. For 3.1-, look at the original gist (under "Revisions")
"""
import gzip
def gzip_str(string_: str) -> bytes:
return gzip.compress(string_.encode())
from flask import after_this_request, request
from io import BytesIO as IO
import gzip
import functools
def gzipped(f):
@functools.wraps(f)
def view_func(*args, **kwargs):
@after_this_request
def zipper(response):