Created
November 29, 2023 19:33
-
-
Save chapmanjacobd/f85f95523101efcb30b052ee660dd147 to your computer and use it in GitHub Desktop.
gunzip requests stream
This file contains 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
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