(self, zinfo, force_zip64=False)
| 1793 | raise |
| 1794 | |
| 1795 | def _open_to_write(self, zinfo, force_zip64=False): |
| 1796 | if force_zip64 and not self._allowZip64: |
| 1797 | raise ValueError( |
| 1798 | "force_zip64 is True, but allowZip64 was False when opening " |
| 1799 | "the ZIP file." |
| 1800 | ) |
| 1801 | if self._writing: |
| 1802 | raise ValueError("Can't write to the ZIP file while there is " |
| 1803 | "another write handle open on it. " |
| 1804 | "Close the first handle before opening another.") |
| 1805 | |
| 1806 | # Size and CRC are overwritten with correct data after processing the file |
| 1807 | zinfo.compress_size = 0 |
| 1808 | zinfo.CRC = 0 |
| 1809 | |
| 1810 | zinfo.flag_bits = 0x00 |
| 1811 | if zinfo.compress_type == ZIP_LZMA: |
| 1812 | # Compressed data includes an end-of-stream (EOS) marker |
| 1813 | zinfo.flag_bits |= _MASK_COMPRESS_OPTION_1 |
| 1814 | if not self._seekable: |
| 1815 | zinfo.flag_bits |= _MASK_USE_DATA_DESCRIPTOR |
| 1816 | |
| 1817 | if not zinfo.external_attr: |
| 1818 | zinfo.external_attr = 0o600 << 16 # permissions: ?rw------- |
| 1819 | |
| 1820 | # Compressed size can be larger than uncompressed size |
| 1821 | zip64 = force_zip64 or (zinfo.file_size * 1.05 > ZIP64_LIMIT) |
| 1822 | if not self._allowZip64 and zip64: |
| 1823 | raise LargeZipFile("Filesize would require ZIP64 extensions") |
| 1824 | |
| 1825 | if self._seekable: |
| 1826 | self.fp.seek(self.start_dir) |
| 1827 | zinfo.header_offset = self.fp.tell() |
| 1828 | |
| 1829 | self._writecheck(zinfo) |
| 1830 | self._didModify = True |
| 1831 | |
| 1832 | self.fp.write(zinfo.FileHeader(zip64)) |
| 1833 | |
| 1834 | self._writing = True |
| 1835 | return _ZipWriteFile(self, zinfo, zip64) |
| 1836 | |
| 1837 | def extract(self, member, path=None, pwd=None): |
| 1838 | """Extract a member from the archive to the current working directory, |
no test coverage detected