Put the bytes from filename into the archive under the name arcname.
(self, filename, arcname=None,
compress_type=None, compresslevel=None)
| 1954 | " would require ZIP64 extensions") |
| 1955 | |
| 1956 | def write(self, filename, arcname=None, |
| 1957 | compress_type=None, compresslevel=None): |
| 1958 | """Put the bytes from filename into the archive under the name |
| 1959 | arcname.""" |
| 1960 | if not self.fp: |
| 1961 | raise ValueError( |
| 1962 | "Attempt to write to ZIP archive that was already closed") |
| 1963 | if self._writing: |
| 1964 | raise ValueError( |
| 1965 | "Can't write to ZIP archive while an open writing handle exists" |
| 1966 | ) |
| 1967 | |
| 1968 | zinfo = ZipInfo.from_file(filename, arcname, |
| 1969 | strict_timestamps=self._strict_timestamps) |
| 1970 | |
| 1971 | if zinfo.is_dir(): |
| 1972 | zinfo.compress_size = 0 |
| 1973 | zinfo.CRC = 0 |
| 1974 | self.mkdir(zinfo) |
| 1975 | else: |
| 1976 | if compress_type is not None: |
| 1977 | zinfo.compress_type = compress_type |
| 1978 | else: |
| 1979 | zinfo.compress_type = self.compression |
| 1980 | |
| 1981 | if compresslevel is not None: |
| 1982 | zinfo.compress_level = compresslevel |
| 1983 | else: |
| 1984 | zinfo.compress_level = self.compresslevel |
| 1985 | |
| 1986 | with open(filename, "rb") as src, self.open(zinfo, 'w') as dest: |
| 1987 | shutil.copyfileobj(src, dest, 1024*8) |
| 1988 | |
| 1989 | def writestr(self, zinfo_or_arcname, data, |
| 1990 | compress_type=None, compresslevel=None): |
no test coverage detected