Download tools/stream_extract.py from SamChen567/Video-XL-Pro-Union: direct link, hf CLI and curl.
- Browser
- Download file 922 Bytes
-
https://huggingface.co/datasets/SamChen567/Video-XL-Pro-Union/resolve/main/tools/stream_extract.py
- Command line
-
hf download hf://datasets/SamChen567/Video-XL-Pro-Union/tools/stream_extract.py
-
curl -L -o stream_extract.py https://huggingface.co/datasets/SamChen567/Video-XL-Pro-Union/resolve/main/tools/stream_extract.py
922 Bytes
| # Stream split tar.gz parts into tar, deleting each part once fully consumed (keeps disk peak ~1 part). | |
| # usage: stream_extract.py <dest> <transform or -> <part...> | |
| import subprocess, sys, os, shutil | |
| CAP = 14_500_000_000_000 | |
| dest, xf, parts = sys.argv[1], sys.argv[2], sys.argv[3:] | |
| if os.path.exists('/root/datasets/tools/STOP'): | |
| sys.exit('STOP flag present') | |
| os.makedirs(dest, exist_ok=True) | |
| cmd = ['tar', 'xzf', '-', '-C', dest] + ([] if xf == '-' else ['--transform', xf]) | |
| p = subprocess.Popen(cmd, stdin=subprocess.PIPE) | |
| for part in parts: | |
| used = shutil.disk_usage('/').used | |
| if used + 50_000_000_000 > CAP: | |
| p.kill(); sys.exit(f'REFUSE near cap used={used} at {part}') | |
| with open(part, 'rb') as f: | |
| shutil.copyfileobj(f, p.stdin, 16 << 20) | |
| os.remove(part) | |
| print('consumed+removed', part, flush=True) | |
| p.stdin.close() | |
| rc = p.wait() | |
| print('tar rc', rc, dest, flush=True) | |
| sys.exit(rc) | |