js: add experimental interface for integrating rclone into browsers
This works by compiling rclone to wasm and exporting the RC api to javascript.
This commit is contained in:
parent
3a14b1d5a9
commit
aab9aa8a2e
8 changed files with 830 additions and 0 deletions
36
fs/rc/js/loader.js
Normal file
36
fs/rc/js/loader.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
var rc;
|
||||
var rcValidResolve
|
||||
var rcValid = new Promise(resolve => {
|
||||
rcValidResolve = resolve
|
||||
});
|
||||
|
||||
var script = document.createElement('script');
|
||||
script.src = "wasm_exec.js";
|
||||
script.onload = function () {
|
||||
if (!WebAssembly.instantiateStreaming) { // polyfill
|
||||
WebAssembly.instantiateStreaming = async (resp, importObject) => {
|
||||
const source = await (await resp).arrayBuffer();
|
||||
return await WebAssembly.instantiate(source, importObject);
|
||||
};
|
||||
}
|
||||
const go = new Go();
|
||||
WebAssembly.instantiateStreaming(fetch("rclone.wasm"), go.importObject).then((result) => {
|
||||
go.run(result.instance);
|
||||
});
|
||||
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
|
||||
rcValid.then(() => {
|
||||
// Some examples of using the rc call
|
||||
//
|
||||
// The rc call takes two parameters, method and input object and
|
||||
// returns an output object.
|
||||
//
|
||||
// If the output object has an "error" and a "status" then it is an
|
||||
// error (it would be nice to signal this out of band).
|
||||
console.log("core/version", rc("core/version", null))
|
||||
console.log("core/version", rc("rc/noop", {"string":"one",number:2}))
|
||||
console.log("core/version", rc("operations/mkdir", {"fs":":memory:","remote":"bucket"}))
|
||||
console.log("core/version", rc("operations/list", {"fs":":memory:","remote":"bucket"}))
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue