Skip to content

Instantly share code, notes, and snippets.

@jeonghwan-kim
Created March 6, 2014 13:23
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 jeonghwan-kim/9389597 to your computer and use it in GitHub Desktop.
Save jeonghwan-kim/9389597 to your computer and use it in GitHub Desktop.
encode image file by base64
var fs = require('fs');
if (process.argv.length < 3) {
throw new Error('Input file name');
}
var f = process.argv[2];
fs.readFile(f, 'utf8', function (err, data) {
if (err) {
throw err;
}
var decodedImage = new Buffer(data, 'base64');
fs.writeFile('decoded-' + f, decodedImage, 'binary', function (err) {});
});
var fs = require('fs');
if (process.argv.length < 3) {
throw new Error('Input file name');
}
var f = process.argv[2];
fs.readFile(f, function (err, data) {
if (err) {
throw err;
}
var base64Image = new Buffer(data).toString('base64');
fs.writeFile('encoded-' + f, base64Image, 'binary', function (err) {});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment