Close the file, and for mode 'w', 'x' and 'a' write the ending records.
(self)
| 2059 | self.close() |
| 2060 | |
| 2061 | def close(self): |
| 2062 | """Close the file, and for mode 'w', 'x' and 'a' write the ending |
| 2063 | records.""" |
| 2064 | if self.fp is None: |
| 2065 | return |
| 2066 | |
| 2067 | if self._writing: |
| 2068 | raise ValueError("Can't close the ZIP file while there is " |
| 2069 | "an open writing handle on it. " |
| 2070 | "Close the writing handle before closing the zip.") |
| 2071 | |
| 2072 | try: |
| 2073 | if self.mode in ('w', 'x', 'a') and self._didModify: # write ending records |
| 2074 | with self._lock: |
| 2075 | if self._seekable: |
| 2076 | self.fp.seek(self.start_dir) |
| 2077 | self._write_end_record() |
| 2078 | finally: |
| 2079 | fp = self.fp |
| 2080 | self.fp = None |
| 2081 | self._fpclose(fp) |
| 2082 | |
| 2083 | def _write_end_record(self): |
| 2084 | for zinfo in self.filelist: # write central directory |