Put the bytes from filename into the archive under the name arcname.
(self, filename, arcname=None,
compress_type=None, compresslevel=None)
| 1781 | " would require ZIP64 extensions") |
| 1782 | |
| 1783 | def write(self, filename, arcname=None, |
| 1784 | compress_type=None, compresslevel=None): |
| 1785 | """Put the bytes from filename into the archive under the name |
| 1786 | arcname.""" |
| 1787 | if not self.fp: |
| 1788 | raise ValueError( |
| 1789 | "Attempt to write to ZIP archive that was already closed") |
| 1790 | if self._writing: |
| 1791 | raise ValueError( |
| 1792 | "Can't write to ZIP archive while an open writing handle exists" |
| 1793 | ) |
| 1794 | |
| 1795 | zinfo = ZipInfo.from_file(filename, arcname, |
| 1796 | strict_timestamps=self._strict_timestamps) |
| 1797 | |
| 1798 | if zinfo.is_dir(): |
| 1799 | zinfo.compress_size = 0 |
| 1800 | zinfo.CRC = 0 |
| 1801 | self.mkdir(zinfo) |
| 1802 | else: |
| 1803 | if compress_type is not None: |
| 1804 | zinfo.compress_type = compress_type |
| 1805 | else: |
| 1806 | zinfo.compress_type = self.compression |
| 1807 | |
| 1808 | if compresslevel is not None: |
| 1809 | zinfo._compresslevel = compresslevel |
| 1810 | else: |
| 1811 | zinfo._compresslevel = self.compresslevel |
| 1812 | |
| 1813 | with open(filename, "rb") as src, self.open(zinfo, 'w') as dest: |
| 1814 | shutil.copyfileobj(src, dest, 1024*8) |
| 1815 | |
| 1816 | def writestr(self, zinfo_or_arcname, data, |
| 1817 | compress_type=None, compresslevel=None): |
no test coverage detected