Close the file, and for mode 'w', 'x' and 'a' write the ending records.
(self)
| 1894 | self.close() |
| 1895 | |
| 1896 | def close(self): |
| 1897 | """Close the file, and for mode 'w', 'x' and 'a' write the ending |
| 1898 | records.""" |
| 1899 | if self.fp is None: |
| 1900 | return |
| 1901 | |
| 1902 | if self._writing: |
| 1903 | raise ValueError("Can't close the ZIP file while there is " |
| 1904 | "an open writing handle on it. " |
| 1905 | "Close the writing handle before closing the zip.") |
| 1906 | |
| 1907 | try: |
| 1908 | if self.mode in ('w', 'x', 'a') and self._didModify: # write ending records |
| 1909 | with self._lock: |
| 1910 | if self._seekable: |
| 1911 | self.fp.seek(self.start_dir) |
| 1912 | self._write_end_record() |
| 1913 | finally: |
| 1914 | fp = self.fp |
| 1915 | self.fp = None |
| 1916 | self._fpclose(fp) |
| 1917 | |
| 1918 | def _write_end_record(self): |
| 1919 | for zinfo in self.filelist: # write central directory |