Created
July 19, 2016 15:51
-
-
Save bradj/952cca7b0bf70652ecd0e31b7c935859 to your computer and use it in GitHub Desktop.
Encode file to base64 and outputs in console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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