MCPcopy
hub / github.com/pex-tool/pex / write_ex

Method write_ex

pex/common.py:392–422  ·  view source on GitHub ↗
(
        self,
        filename,  # type: Text
        arcname=None,  # type: Optional[Text]
        date_time=None,  # type: Optional[time.struct_time]
        file_mode=None,  # type: Optional[int]
        digest=None,  # type: Optional[Digest]
        compress=True,  # type: bool
    )

Source from the content-addressed store, hash-verified

390 return self.write_ex(filename, arcname=arcname, digest=digest, compress=compress)
391
392 def write_ex(
393 self,
394 filename, # type: Text
395 arcname=None, # type: Optional[Text]
396 date_time=None, # type: Optional[time.struct_time]
397 file_mode=None, # type: Optional[int]
398 digest=None, # type: Optional[Digest]
399 compress=True, # type: bool
400 ):
401 # type: (...) -> int
402 zip_info, is_dir = self.zip_info_from_file(
403 filename, arcname=arcname, date_time=date_time, file_mode=file_mode, compress=compress
404 )
405 size = 0
406 if is_dir:
407 self.writestr(zip_info, b"")
408 elif sys.version_info[:2] >= (3, 6):
409 with closing(self.open(zip_info, "w")) as dst_fp, open(filename, "rb") as src_fp:
410 for chunk in iter(lambda: src_fp.read(io.DEFAULT_BUFFER_SIZE), b""):
411 size += len(chunk)
412 if digest:
413 digest.update(chunk)
414 dst_fp.write(chunk)
415 else:
416 with open(filename, "rb") as fp:
417 data = fp.read()
418 size = len(data)
419 if digest:
420 digest.update(data)
421 self.writestr(zip_info, data)
422 return size
423
424 def _extract_member(
425 self,

Callers 2

write_deterministicMethod · 0.95
create_whlFunction · 0.80

Calls 5

zip_info_from_fileMethod · 0.95
openMethod · 0.80
readMethod · 0.45
updateMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected