Datasets:
Download code/dynamic_demo/fetch_cache.py from Heiheihaha17/MESH-Benchmark: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/datasets/Heiheihaha17/MESH-Benchmark/resolve/main/code/dynamic_demo/fetch_cache.py
- Command line
-
hf download hf://datasets/Heiheihaha17/MESH-Benchmark/code/dynamic_demo/fetch_cache.py
-
curl -L -o fetch_cache.py https://huggingface.co/datasets/Heiheihaha17/MESH-Benchmark/resolve/main/code/dynamic_demo/fetch_cache.py
1.34 kB
| """Download verified frozen RIR cache archives from the public demo URL.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import tempfile | |
| import urllib.request | |
| from zipfile import ZipFile | |
| from .common import sha | |
| def main(): | |
| p=argparse.ArgumentParser();p.add_argument('--base-url',required=True);p.add_argument('--work',type=Path,required=True) | |
| a=p.parse_args();base=a.base_url.rstrip('/')+'/' | |
| with urllib.request.urlopen(base+'cache/manifest.json',timeout=60) as response:manifest=json.load(response) | |
| out=a.work/'rirs';out.mkdir(parents=True,exist_ok=True) | |
| with tempfile.TemporaryDirectory() as temp: | |
| for record in manifest['archives']: | |
| archive=Path(temp)/Path(record['path']).name | |
| urllib.request.urlretrieve(base+record['path'],archive) | |
| if sha(archive)!=record['sha256']:raise ValueError('Cache download checksum mismatch') | |
| with ZipFile(archive) as z: | |
| for name in z.namelist(): | |
| path=Path(name) | |
| if path.is_absolute() or len(path.parts)!=1 or path.suffix not in ('.json','.npy'): | |
| raise ValueError('Unexpected cache archive entry') | |
| z.extractall(out) | |
| print('Verified',record['path']) | |
| if __name__=='__main__':main() | |