Skip to content

Instantly share code, notes, and snippets.

@oxr463
Last active April 26, 2021 16:16
Show Gist options
  • Save oxr463/b52e27bf9ac537979c62183f313e0bd0 to your computer and use it in GitHub Desktop.
Save oxr463/b52e27bf9ac537979c62183f313e0bd0 to your computer and use it in GitHub Desktop.
Encode/Decode binary as base64
#!/usr/bin/env node
// SPDX-License-Identifier: MIT
// Decode binary from base64
const fs = require("fs");
const process = require("process");
const util = require("util");
process.argv.forEach(function (val, index, array) {
const txt = fs.readFileSync(val);
const bin = Buffer.from(txt,'base64').toString();
console.log(util.inspect(bin, { maxArrayLength: null }));
});
#!/usr/bin/env node
// SPDX-License-Identifier: MIT
// Encode binary as base64
const fs = require("fs");
const process = require("process");
const util = require("util");
process.argv.forEach(function (val, index, array) {
if(val.includes(".bin" || ".hex")) {
const bin = fs.readFileSync(val);
const txt = Buffer.from(bin).toString('base64');
console.log(util.inspect(txt, { maxArrayLength: null }));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment