Skip to content

Commit

Permalink
No need to encode in base64
Browse files Browse the repository at this point in the history
  • Loading branch information
healeycodes committed Dec 29, 2023
1 parent 26f4958 commit dcf9aad
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions wasm/wat2wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@ const compile = (source) => {
const binaryOutput = module.toBinary({ log: true, write_debug_names: true });
const outputLog = binaryOutput.log;
const binaryBuffer = binaryOutput.buffer;
// binaryBuffer is Uint8Array
const outputBase64 = btoa(String.fromCharCode.apply(null, binaryBuffer));

// send debug details to stderr
console.error({ binaryOutput, outputLog, binaryBuffer })
// send base64 wasm binary to stdout
console.log(outputBase64)

// test that fib works!
const wasmBuffer = Buffer.from(outputBase64, 'base64');
WebAssembly.instantiate(wasmBuffer, {})
WebAssembly.instantiate(binaryBuffer, {})
.then(result => {
const func = result.instance.exports.fib;
console.log('Calling with:', 25)
Expand Down

0 comments on commit dcf9aad

Please sign in to comment.