preprocess-wasm-bytes
v0.1.8
Published
Preprocess a WebAssembly binary by adding exports for table-referenced functions, mutable globals, memories, and tables.
Readme
License: UNLICENSED — Not licensed for use; all rights reserved.
preprocess-wasm-bytes
Exports a single function:
preprocess_wasm_bytes(bytes: Uint8Array): Promise<Uint8Array>
It scans the WASM binary (imports/exports/globals/memories/tables/element segments) and produces a new WASM binary with additional exports added for:
- functions referenced by element segments /
ref.funcin const-exprs - mutable globals
- all memories
- all tables
Install
npm i preprocess-wasm-bytes
Usage (Node / ESM)
import fs from "node:fs";
import { preprocess_wasm_bytes } from "preprocess-wasm-bytes";
const bytes = new Uint8Array(fs.readFileSync("input.wasm"));
const out = await preprocess_wasm_bytes(bytes);
fs.writeFileSync("output.wasm", out);
Usage (Browser bundlers)
import { preprocess_wasm_bytes } from "preprocess-wasm-bytes";
const res = await fetch("/module.wasm");
const bytes = new Uint8Array(await res.arrayBuffer());
const out = await preprocess_wasm_bytes(bytes);
Debug logging
globalThis.__WASM_PREPROCESS_DEBUG__ = true;
Set that before calling preprocess_wasm_bytes(...).