File size: 871 Bytes
77b49a9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // 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`);
|