File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -62,10 +62,9 @@ def _get_file(self):
6262 )
6363 if "r" in self ._mode :
6464 self ._is_dirty = False
65+ # This automatically decompresses the file
6566 self .blob .download_to_file (self ._file , checksum = "crc32c" )
6667 self ._file .seek (0 )
67- if self ._storage .gzip and self .blob .content_encoding == "gzip" :
68- self ._file = self ._decompress_file (mode = self ._mode , file = self ._file )
6968 return self ._file
7069
7170 def _set_file (self , value ):
Original file line number Diff line number Diff line change 1414from google .cloud .storage .retry import DEFAULT_RETRY
1515
1616from storages .backends import gcloud
17+ from storages .backends .gcloud import GoogleCloudFile
1718
1819
1920class GCloudTestCase (TestCase ):
@@ -571,3 +572,17 @@ def test_storage_save_gzip(self, *args):
571572 self .assertEqual (zfile .read (), b"I should be gzip'd" )
572573 finally :
573574 patcher .stop ()
575+
576+ def test_storage_read_gzip (self , * args ):
577+ """
578+ Test reading a gzipped file decompresses content only once.
579+ """
580+ name = "test_storage_save.css"
581+ file = GoogleCloudFile (name , "rb" , self .storage )
582+ blob = mock .MagicMock ()
583+ file .blob = blob
584+ blob .download_to_file = lambda f , checksum = None : f .write (b"No gzip" )
585+ blob .content_encoding = "gzip"
586+ f = file ._get_file ()
587+
588+ f .read () # This should not fail
You can’t perform that action at this time.
0 commit comments