INNER CODE UNIT · Python
extract_verified
KSwordDEV/KSword · GhidraRuntimePlugin/package.py:80
def extract_verified(path: Path, profile: dict, output: Path) -> list[dict]:
destination = output / profile['destination_directory']
inventory = []
with zipfile.ZipFile(path) as archive:
for entry in sorted(archive.infolist(), key=lambda item: item.filename):
relative = safe_member(entry.filename, profile['root_directory'])
target = destination.joinpath(*relative.parts)
# Output is exclusively newly created. No rename/delete/overwrite,
# no links; the relative path was checked before this extraction.
if entry.is_dir():
target.mkdir(parents=True, exist_ok=True)
continue
target.parent.mkdir(parents=True, exist_ok=True)
digest = hashlib.sha256()
count = 0
with archive.open(entry) as source, target.open('xb') as sink:
for block in iter(lambda: source.read(1024 * 1024), b''):
digest.update(block)