amirulofficialinfy's picture
Add files using upload-large-folder tool
81f161c verified
raw
history blame
885 Bytes
#!/usr/bin/env python3
import os, tarfile, math, json
from pathlib import Path
IMAGE_DIR = Path("images") # all PNGs live here now
META_JSON = Path("metadata.json")
PER_SHARD = 10_000 # ≤ 10 000 files per tar
OUT_DIR = Path(".") # tars are written next to script
# 1. load metadata so we keep ordering consistent
with META_JSON.open() as f:
meta = json.load(f)
all_names = sorted(meta)
n_shards = math.floor((len(all_names)-1) / PER_SHARD) + 1
for s in range(n_shards):
start = s * PER_SHARD
end = min((s+1)*PER_SHARD - 1, len(all_names) - 1)
shard_name = OUT_DIR / f"images-{start:05d}-{end:05d}.tar"
print(f" → building {shard_name}")
with tarfile.open(shard_name, "w") as tar:
for fname in all_names[start:end+1]:
tar.add(IMAGE_DIR / fname, arcname=fname)