summaryrefslogtreecommitdiffstats
path: root/Lib/gzip.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r--Lib/gzip.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 21d83e6..deaf15d 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -503,19 +503,21 @@ class GzipFile(io.BufferedIOBase):
return self.fileobj is None
def close(self):
- if self.fileobj is None:
+ fileobj = self.fileobj
+ if fileobj is None:
return
- if self.mode == WRITE:
- self.fileobj.write(self.compress.flush())
- write32u(self.fileobj, self.crc)
- # self.size may exceed 2GB, or even 4GB
- write32u(self.fileobj, self.size & 0xffffffff)
- self.fileobj = None
- elif self.mode == READ:
- self.fileobj = None
- if self.myfileobj:
- self.myfileobj.close()
- self.myfileobj = None
+ self.fileobj = None
+ try:
+ if self.mode == WRITE:
+ fileobj.write(self.compress.flush())
+ write32u(fileobj, self.crc)
+ # self.size may exceed 2GB, or even 4GB
+ write32u(fileobj, self.size & 0xffffffff)
+ finally:
+ myfileobj = self.myfileobj
+ if myfileobj:
+ self.myfileobj = None
+ myfileobj.close()
def flush(self,zlib_mode=zlib.Z_SYNC_FLUSH):
self._check_closed()