1、普通字符串
//編碼 new Buffer(String).toString('base64'); //解碼 new Buffer(base64Str, 'base64').toString();
2、十六進制Hex
//編碼 new Buffer(String, 'base64').toString('hex'); //解碼 new Buffer(base64Str, 'hex').toString('utf8');
3、圖片
const fs = require('fs');
//編碼
function base64_encode(file) {
let bitmap = fs.readFileSync(file);
return new Buffer(bitmap).toString('base64');
}
//解碼
function base64_decode(base64str, file) {
var bitmap = new Buffer(base64str, 'base64');
fs.writeFileSync(file, bitmap);
}
