![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
The JavaScript API to the "Swiss army knife of cloud storage" rclone.
Besides providing a way to install rclone on different platforms, a CLI and a JavaScript API are included.
npm install rclone.js
After installation, the latest binary of rclone
is also fetched based on
your system environment.
If a custom version of rclone
binary is needed, use RCLONE_EXECUTABLE
environment variable to set the path to that custom binary.
Except selfupdate
, which is used to update rclone
binary, all API functions
return a child process whose events we can listen to. Optional flags can be
passed as an object to the last argument of the function call. Except removing
the --
prefix, there is no other conversion to the flag name. JSON values are
stringified before passed to rclone
.
Each API functions can also take options for the spawned child process. See https://nodejs.org/api/child_process.html#child_processspawncommand-args-options for their documentation.
const rclone = require("rclone.js");
const ls = rclone.ls("source:", {
"max-depth": 1,
// Spawn options:
"env": {
RCLONE_CONFIG: "~/.config/rclone/rclone.conf",
},
"shell": "/bin/sh",
});
ls.stdout.on("data", (data) => {
console.log(data.toString());
});
ls.stderr.on("data", (data) => {
console.error(data.toString());
});
There is also a Promise-based API:
const rclone = require("rclone.js").promises;
(async function() {
const results = await rclone.ls("source:", {
"max-depth": 1,
// Spawn options:
"env": {
RCLONE_CONFIG: "~/.config/rclone/rclone.conf",
},
"shell": "/bin/sh",
});
console.log(results);
})();
When the official rclone
adds new command that has not been provided here,
we can still use the command through the default exported functions, passing
the command name as first argument:
const rclone = require("rclone.js");
rclone("newcommand", "source:", "target:", {
"flag": true,
});
(async function() {
const results = await rclone.promises("newcommand", "source:", "target:", {
"flag": true,
});
console.log(results);
})();
This simple CLI calls the JS API above and outputs stdout
and stderr
.
$ npx rclone --version
rclone v1.54.0
- os/arch: darwin/amd64
- go version: go1.15.7
$ npx rclone ls source: --max-depth 1
-1 2020-12-12 10:01:44 -1 Documents
-1 2020-12-11 16:24:20 -1 Pictures
The CLI also supports executing a custom JS-based command to further extend
usage outside of what the official rclone
offers:
$ npx rclone echo.js arg1 --string value arg2 --boolean
The custom JS file just needs to export a function that takes the arguments and
flags parsed from the CLI. It can either return a child process, or a Promise
.
For a child process, its stdout
and stderr
are piped to the caller process.
Inside the function, this
is set to rclone.js
module.
const { spawn } = require("child_process");
module.exports = function echo(arg1, arg2, flags = {}) {
return spawn("echo", [arg1, arg2, JSON.stringify(flags)]);
}
The custom module is loaded through require
, so it has some nice advantages
when locating module:
.js
extension, custom
is same as custom.js
.foobar.js
and foobar/index.js
.NODE_PATH
environment variable.node_modules
by its name.With that, there are a few things custom commands can be used:
archive
.For a "real-life" example, check out selfupdate, which
overrides the built-in selfupdate
command to download rclone executable if it
has not been downloaded yet. Consecutive runs just call selfupdate
API.
For publishing a custom rclone
command as NPM package, consider prefixing the
package name with rclone-
so it's clearer and not conflicting.
FAQs
JavaScript API for rclone
We found that rclone.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.