add wasm qr decode
This commit is contained in:
14
deno_wasm_qr/parse_qr.ts
Normal file
14
deno_wasm_qr/parse_qr.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
const wasmCode = await Deno.readFile("./decodeqr/target/wasm32-unknown-unknown/release/decodeqr.wasm");
|
||||
const wasmModule = new WebAssembly.Module(wasmCode);
|
||||
const wasmInstance = new WebAssembly.Instance(wasmModule);
|
||||
|
||||
const linearMemory = wasmInstance.exports.memory;
|
||||
|
||||
function readString(memory, ptr) {
|
||||
const mem = new Uint8Array(memory.buffer, ptr);
|
||||
let length;
|
||||
for (length = 0; mem[length] !== 0; length ++);
|
||||
return new TextDecoder("utf-8").decode(new Uint8Array(mem.buffer, ptr, length));
|
||||
}
|
||||
|
||||
console.log(readString(linearMemory, wasmInstance.exports.parse_default_qr()));
|
||||
Reference in New Issue
Block a user