Video-XL-Pro-Union / tools /stream_extract.py
SamChen567's picture
Upload folder using huggingface_hub
30ba310 verified
Raw History Blame Contribute Delete
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)