我在 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 中保存文件或将其流式传输到某处。