Skip to content

Instantly share code, notes, and snippets.

@viesti
Created May 2, 2019 15:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viesti/91c711a6ab1881f87337f8af713b6133 to your computer and use it in GitHub Desktop.
Save viesti/91c711a6ab1881f87337f8af713b6133 to your computer and use it in GitHub Desktop.
Stream and decompress a gzip file from S3
import boto3
import zlib
def decompress_object(bucket, key, out_file):
s3 = boto3.client("s3")
body = s3.get_object(Bucket=bucket, Key=key)['Body']
with open(out_file, "ab") as out:
decompressor = zlib.decompressobj(zlib.MAX_WBITS|32)
for chunk in body.iter_chunks():
out.write(decompressor.decompress(chunk))
decompressor.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment