unroll / tests /pack_bin.mjs
SharpMeow's picture
Faster first load: ship the int16 geometry as byte planes + gzip (scroll.i16p.gz, 1.62 MB instead of 3.48 MB), unpacked in the browser to the exact scroll.bin bytes with a fallback to scroll.bin; tools/pack_bin.py builds it, tests/pack_bin.mjs checks the round trip
77b49a9
Raw History Blame Contribute Delete
871 Bytes
// Regression + benchmark: data/scroll.i16p.gz unpacks to exactly data/scroll.bin.
// Run: node tests/pack_bin.mjs (needs the LFS files pulled)
import { readFileSync } from 'node:fs';
import { createHash } from 'node:crypto';
import { unpackInt16 } from '../lib/formats.js';
const root = new URL('..', import.meta.url).pathname;
const raw = readFileSync(root + 'data/scroll.bin'), packed = readFileSync(root + 'data/scroll.i16p.gz');
const h = (b) => createHash('sha256').update(Buffer.from(b)).digest('hex');
const t = performance.now();
const out = await unpackInt16(packed);
const ms = performance.now() - t;
if (h(out) !== h(raw)) { console.error('FAIL: unpacked bytes differ from scroll.bin'); process.exit(1); }
console.log(`ok ${raw.length} B plain, ${packed.length} B packed (${(100 * packed.length / raw.length).toFixed(1)} %), unpack ${ms.toFixed(1)} ms`);