【发布时间】:2020-05-05 02:15:08
【问题描述】:
我在 WebAssembly 代码中有一个 u8[] 数组,如何在常规 JS 中读取它?调用它只会给我一个 i32。
// Load module WebAssembly.Instance
const instance = await getInstance("./build/embed.wasm");
// Try to get the array of bytes from the module
const embeddedFileBytes = Uint8Array.from(instance.fileBytes);
// write the file to disc
await writeFile("./output.text", embeddedFileBytes);
// check the hash is the same as the original file that was embedded
expect(sha1("./output.text")).toEqual(sha1("./input.text"))
webassembly 模块有一个导出:
export const fileBytes: u8[] = [83,65,77,80,76,69,10];
【问题讨论】:
-
您能提供您工作的任何示例代码吗?否则我不能举个例子。
-
添加示例代码感谢@BumsikKim
-
谢谢,但是那个 WebAssembly 模块是用什么写的?它只是一个单行吗?还有
getInstance()是什么?它不是标准的 WebAssembly API,那么您为 JS 代码使用了什么样的库?由于您已经没有使用“常规 JS”,请提供更具体的上下文... -
请注意,这不仅仅是关于 WebAssembly 的问题,而是关于 WebAssembly 框架的问题。所以你可能想在你的问题中添加额外的标签。
标签: webassembly assemblyscript