Skip to content

Commit

Permalink
Fixed #383 -- Stream large file reads from S3
Browse files Browse the repository at this point in the history
  • Loading branch information
tveastman authored and jschneier committed Aug 12, 2018
1 parent 08e3da2 commit ea0986d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion storages/backends/s3boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class S3Boto3StorageFile(File):
buffer_size = setting('AWS_S3_FILE_BUFFER_SIZE', 5242880)

def __init__(self, name, mode, storage, buffer_size=None):
if 'r' in mode and 'w' in mode:
raise ValueError("Can't combine 'r' and 'w' in mode.")
self._storage = storage
self.name = name[len(self._storage.location):].lstrip('/')
self._mode = mode
Expand Down Expand Up @@ -93,7 +95,7 @@ def _get_file(self):
)
if 'r' in self._mode:
self._is_dirty = False
self._file.write(self.obj.get()['Body'].read())
self.obj.download_fileobj(self._file)
self._file.seek(0)
if self._storage.gzip and self.obj.content_encoding == 'gzip':
self._file = GzipFile(mode=self._mode, fileobj=self._file, mtime=0.0)
Expand Down

0 comments on commit ea0986d

Please sign in to comment.