-
-
Notifications
You must be signed in to change notification settings - Fork 889
Open
Description
For the S3 backend, if a file is gzipped/compressed, open will always open the file in binary mode.
Here's the rough code path:
self._decompress_file is called here:
django-storages/storages/backends/s3.py
Lines 184 to 185 in 3658c3d
| if self._storage.gzip and self.obj.content_encoding == "gzip": | |
| self._file = self._decompress_file(mode=self._mode, file=self._file) |
Defined on this mixin:
django-storages/storages/compress.py
Lines 48 to 49 in ca89a94
| def _decompress_file(self, mode, file, mtime=0.0): | |
| return GzipFile(mode=mode, fileobj=file, mtime=mtime) |
Consulting the python docs for GzipFile: https://docs.python.org/3/library/gzip.html#gzip.GzipFile
"Note that the file is always opened in binary mode. To open a compressed file in text mode, use open() (or wrap your GzipFile with an io.TextIOWrapper)."
Solution is to either use gzip.open or explicitly wrap the GzipFile in a TextIOWrapper
Metadata
Metadata
Assignees
Labels
No labels