Skip to content

Instantly share code, notes, and snippets.

@dustyfresh
Created March 30, 2020 22:48
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 dustyfresh/28b02389e3b8465fa08fcb95db703796 to your computer and use it in GitHub Desktop.
Save dustyfresh/28b02389e3b8465fa08fcb95db703796 to your computer and use it in GitHub Desktop.
read gzipped data from a remote file as a string
import io
import gzip
import requests
data = requests.get('https://url/file.txt.gz', stream=True)
in_ = io.BytesIO()
in_.write(data.content)
in_.seek(0)
gunzipped_bytes_obj = gzip.GzipFile(fileobj=in_, mode='rb').read()
data = gunzipped_bytes_obj.decode()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment