2 * Reading a reference .h5 in the page.
3 *
4 * h5wasm's browser build carries the whole HDF5 library as embedded wasm —
5 * about 4 MB — so it is imported here, dynamically, and nowhere else: the page
6 * pays for it on the first file actually loaded, never on startup. The bytes
7 * are written into the wasm module's in-memory filesystem under a fixed
8 * scratch name (loads are sequential — there is one file input), opened,
9 * extracted, and unlinked.
10 */
11import { extractReferenceCase, type H5Node, type ReferenceCase } from './referenceCase.ts';
13const SCRATCH = '/loaded-reference.h5';
15export async function loadReferenceFile(file: File): Promise<ReferenceCase> {
16 const bytes = new Uint8Array(await file.arrayBuffer());
17 const h5 = await import('h5wasm');
18 const { FS } = (await h5.ready) as unknown as {
19 FS: { writeFile(path: string, data: Uint8Array): void; unlink(path: string): void };
20 };
21 FS.writeFile(SCRATCH, bytes);
22 const opened = new h5.File(SCRATCH, 'r');
23 try {
24 return extractReferenceCase(opened as unknown as H5Node, file.name);
25 } finally {
26 opened.close();
27 FS.unlink(SCRATCH);
28 }
29}