Created
March 6, 2014 13:23
-
-
Save jeonghwan-kim/9389597 to your computer and use it in GitHub Desktop.
encode image file by base64
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
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) {}); | |
}); |
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
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