Datasets:
Download pipeline/archive_cache.py from faraway00/StyleEdit: direct link, hf CLI and curl.
- Browser
- Download file 637 Bytes
-
https://huggingface.co/datasets/faraway00/StyleEdit/resolve/main/pipeline/archive_cache.py
- Command line
-
hf download hf://datasets/faraway00/StyleEdit/pipeline/archive_cache.py
-
curl -L -o archive_cache.py https://huggingface.co/datasets/faraway00/StyleEdit/resolve/main/pipeline/archive_cache.py
637 Bytes
| """Root-disk, immutable range cache; only atomic completed chunks are readable.""" | |
| import os | |
| from pathlib import Path | |
| ROOT=Path('/opt/styleedit-archive-cache') | |
| BLOCK=64*1024**2 | |
| def cached_range(category,start,length): | |
| chunks=[]; pos=start; end=start+length | |
| while pos<end: | |
| base=pos//BLOCK*BLOCK | |
| path=ROOT/category/f'{base:012d}.chunk' | |
| try: | |
| with path.open('rb') as f: | |
| f.seek(pos-base); n=min(end-pos,BLOCK-(pos-base)); data=f.read(n) | |
| except FileNotFoundError:return None | |
| if len(data)!=n:return None | |
| chunks.append(data);pos+=n | |
| return b''.join(chunks) | |