taglib-wasm
Version:
TagLib for TypeScript platforms: Deno, Node.js, Bun, Electron, browsers, and Cloudflare Workers
43 lines (42 loc) • 1.19 kB
JavaScript
import createTagLibModule from "../build/taglib-wrapper.js";
let cachedModule = null;
async function loadTagLibModuleStatic(options) {
if (cachedModule && !options) {
return cachedModule;
}
const moduleConfig = {};
if (options?.wasmBinary) {
moduleConfig.wasmBinary = options.wasmBinary;
}
if (options?.wasmUrl) {
moduleConfig.locateFile = (path) => {
if (path.endsWith(".wasm")) {
return options.wasmUrl;
}
return path;
};
}
try {
const module = await createTagLibModule(moduleConfig);
if (!module || !module.HEAPU8) {
throw new Error("Module not initialized: missing HEAPU8");
}
if (!module._malloc || !module.allocate) {
throw new Error(
"Module not initialized: missing memory allocation functions"
);
}
if (!options) {
cachedModule = module;
}
return module;
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
throw new Error(`Failed to load TagLib module: ${message}`);
}
}
var deno_compile_loader_default = loadTagLibModuleStatic;
export {
deno_compile_loader_default as default,
loadTagLibModuleStatic
};