0

我在 WebAssembly wasm 文件中嵌入了一个二进制文件。

考虑这个来源:

embed.ts(使用 AssemblyScript 构建为 embed.wasm):

export const text: u8[] = [83,65,77,80,76,69,10]; // The text "SAMPLE" in UTF-8 encoding

export const textLength: i32 = text.length;

工人.js:

const instance = new WebAssembly.Instance(/* read embed.wasm */).exports;
instance.textLength // prints 7, correct
instance.text // prints, 10232 of type number, ?!?!?

我怎样才能读出这个字节数组来重建嵌入的文件?我需要重新创建 Uint8Array,以便在 worker.js 中保存文件或将其流式传输到某处。

4

1 回答 1

1

当前阶段的 WebAssembly 只能在 wasm 模块和 javascript 主机之间传递数字instance.text,线性内存中的数字(指针)或偏移量也是如此。为了从该内存中读取真实数据,您可以使用__getUint8Array__getArrayloader中读取。还有有用的信息

于 2020-01-18T13:41:51.340 回答