Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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