Skip to content

Instantly share code, notes, and snippets.

@thihenos
Last active June 30, 2018 20:12
Show Gist options
  • Save thihenos/ad76d8f65d5ddd3a365717e5e065532d to your computer and use it in GitHub Desktop.
Save thihenos/ad76d8f65d5ddd3a365717e5e065532d to your computer and use it in GitHub Desktop.
var fs = require('fs');
//Convertendo binario em arquivo
function base64_decode(base64str,fileName){
var bitmap = new Buffer (base64str, 'base64');
fs.writeFileSync('src/temp/'+fileName+'',bitmap, 'binary', function (err){
if(err){
console.log('Conversao com erro');
}
} );
}
//Convertendo arquivo em binário
function base64_encode(fileName){
var bitmap = fs.readFileSync('src/temp/'+fileName+'');
return new Buffer (bitmap).toString('base64');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment