github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/fs/rc/js/loader.js (about) 1 var rc; 2 var rcValidResolve 3 var rcValid = new Promise(resolve => { 4 rcValidResolve = resolve 5 }); 6 7 var script = document.createElement('script'); 8 script.src = "wasm_exec.js"; 9 script.onload = function () { 10 if (!WebAssembly.instantiateStreaming) { // polyfill 11 WebAssembly.instantiateStreaming = async (resp, importObject) => { 12 const source = await (await resp).arrayBuffer(); 13 return await WebAssembly.instantiate(source, importObject); 14 }; 15 } 16 const go = new Go(); 17 WebAssembly.instantiateStreaming(fetch("rclone.wasm"), go.importObject).then((result) => { 18 go.run(result.instance); 19 }); 20 21 }; 22 document.head.appendChild(script); 23 24 rcValid.then(() => { 25 // Some examples of using the rc call 26 // 27 // The rc call takes two parameters, method and input object and 28 // returns an output object. 29 // 30 // If the output object has an "error" and a "status" then it is an 31 // error (it would be nice to signal this out of band). 32 console.log("core/version", rc("core/version", null)) 33 console.log("rc/noop", rc("rc/noop", {"string":"one",number:2})) 34 console.log("operations/mkdir", rc("operations/mkdir", {"fs":":memory:","remote":"bucket"})) 35 console.log("operations/list", rc("operations/list", {"fs":":memory:","remote":"bucket"})) 36 })