"""Reassemble uploaded byte shards into the exact original NPY file.""" import argparse,hashlib,json,shutil from pathlib import Path def sha(path): h=hashlib.sha256() with path.open('rb') as stream: while data:=stream.read(8*1024**2): h.update(data) return h.hexdigest() def main(): parser=argparse.ArgumentParser(description=__doc__) parser.add_argument('--root',type=Path,default=Path(__file__).resolve().parent) args=parser.parse_args();root=args.root.resolve() manifest=json.loads((root/'asset_manifest.json').read_text(encoding='utf-8')) for item in manifest.get('reassemble',[]): target=(root/item['path']).resolve() if not target.is_relative_to(root):raise ValueError('Path escapes asset root') target.parent.mkdir(parents=True,exist_ok=True) if target.exists(): if target.stat().st_size!=item['bytes'] or sha(target)!=item['sha256']: raise ValueError('Existing output differs; refusing overwrite') print('Already verified:',item['path']);continue if shutil.disk_usage(target.parent).free