File size: 1,037 Bytes
d4c5ec7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #!/usr/bin/env python3
"""Pack the v86 runtime pieces and the DOS floppy as gzip+base64 JS in dist/.
HF static Spaces serve binary files through a CORS-less redirect, but text files
are served directly, so everything binary travels as base64 text."""
import base64, gzip, json, os, shutil
from pathlib import Path
root = Path(__file__).resolve().parent.parent
deps = Path(os.environ.get("DEPS", root / "deps"))
dist = root / "dist"; dist.mkdir(exist_ok=True)
parts = {"wasm": deps / "v86/v86.wasm", "bios": deps / "v86/seabios.bin",
"vga": deps / "v86/vgabios.bin", "img": root / "build/dosllm.img"}
assets = {}
for key, path in parts.items():
raw = path.read_bytes(); z = gzip.compress(raw, 9, mtime=0)
assets[key] = base64.b64encode(z).decode()
print(f"{key:5} {len(raw):>8} -> gzip {len(z):>8} -> base64 {len(assets[key]):>8}")
(dist / "assets.b64.js").write_text("window.DOSLLM_ASSETS=" + json.dumps(assets) + ";\n")
shutil.copy(deps / "v86/libv86.js", dist / "libv86.js")
print("wrote", dist / "assets.b64.js")
|