Skip to content

Commit

Permalink
Use context manager with GzipFile (#953)
Browse files Browse the repository at this point in the history
Supported since Python 3.1.
  • Loading branch information
jdufresne committed Nov 12, 2020
1 parent 738347e commit adeb2af
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions storages/backends/s3boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,8 @@ def _compress_content(self, content):
# This means each time a file is compressed it changes even if the other contents don't change
# For S3 this defeats detection of changes using MD5 sums on gzipped files
# Fixing the mtime at 0.0 at compression time avoids this problem
zfile = GzipFile(mode='wb', fileobj=zbuf, mtime=0.0)
try:
with GzipFile(mode='wb', fileobj=zbuf, mtime=0.0) as zfile:
zfile.write(force_bytes(content.read()))
finally:
zfile.close()
zbuf.seek(0)
# Boto 2 returned the InMemoryUploadedFile with the file pointer replaced,
# but Boto 3 seems to have issues with that. No need for fp.name in Boto3
Expand Down

0 comments on commit adeb2af

Please sign in to comment.