Skip to content

Instantly share code, notes, and snippets.

@chapmanjacobd
Created November 29, 2023 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chapmanjacobd/f85f95523101efcb30b052ee660dd147 to your computer and use it in GitHub Desktop.
Save chapmanjacobd/f85f95523101efcb30b052ee660dd147 to your computer and use it in GitHub Desktop.
gunzip requests stream
import zlib
def decompress_stream(stream):
o = zlib.decompressobj(16 + zlib.MAX_WBITS)
for chunk in stream:
yield o.decompress(chunk)
yield o.flush()
r = requests.get(some_url, stream=True)
parseable_data = decompress_stream(r.iter_content(1024))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment