itk-wasm
Version:
High-performance spatial analysis in a web browser, Node.js, and reproducible execution across programming languages and hardware architectures.
27 lines • 1.18 kB
JavaScript
import fs from 'fs';
import { pathToFileURL } from 'url';
import { ZSTDDecoder } from '@thewtex/zstddec';
const zstdDecoder = new ZSTDDecoder();
await zstdDecoder.init();
async function loadEmscriptenModuleNode(modulePath) {
let modulePrefix = modulePath;
if (modulePath.endsWith('.js')) {
modulePrefix = modulePath.substring(0, modulePath.length - 3);
}
if (modulePath.endsWith('.wasm')) {
modulePrefix = modulePath.substring(0, modulePath.length - 5);
}
if (modulePath.endsWith('.wasm.zst')) {
modulePrefix = modulePath.substring(0, modulePath.length - 9);
}
const compressedWasmBinaryPath = `${modulePrefix}.wasm.zst`;
const compressedWasmBinary = fs.readFileSync(compressedWasmBinaryPath);
const wasmBinary = zstdDecoder.decode(new Uint8Array(compressedWasmBinary));
const fullModulePath = pathToFileURL(`${modulePrefix}.js`).href;
const result = await import(
/* webpackIgnore: true */ /* @vite-ignore */ fullModulePath);
const instantiated = result.default({ wasmBinary });
return instantiated;
}
export default loadEmscriptenModuleNode;
//# sourceMappingURL=load-emscripten-module-node.js.map