MCPcopy Index your code
hub / github.com/python/cpython / write

Method write

Lib/zipfile/__init__.py:1956–1987  ·  view source on GitHub ↗

Put the bytes from filename into the archive under the name arcname.

(self, filename, arcname=None,
              compress_type=None, compresslevel=None)

Source from the content-addressed store, hash-verified

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):

Callers 8

writeMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45
_open_to_writeMethod · 0.45
writestrMethod · 0.45
mkdirMethod · 0.45
_write_end_recordMethod · 0.45
addToZipFunction · 0.45

Calls 5

mkdirMethod · 0.95
openMethod · 0.95
openFunction · 0.50
from_fileMethod · 0.45
is_dirMethod · 0.45

Tested by

no test coverage detected