Skip to content

Instantly share code, notes, and snippets.

@bradj
Created July 19, 2016 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradj/952cca7b0bf70652ecd0e31b7c935859 to your computer and use it in GitHub Desktop.
Save bradj/952cca7b0bf70652ecd0e31b7c935859 to your computer and use it in GitHub Desktop.
Encode file to base64 and outputs in console.
const fs = require('fs');
const f = process.argv[2];
fs.access(f, fs.R_OK, (err) => {
if (err) {
kill(`Cannot acces ${f}`);
}
readFile();
});
readFile = () => {
fs.readFile(f, (err, data) => {
if (err) {
kill('Cannot read file', err);
}
console.log(data.toString('base64'));
});
}
kill = (message, err) => {
console.log(message, err || '');
process.exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment