2011-11-29 58 views

回答

28

這個問題有一些有用的信息:How to do Base64 encoding in node.js?

緩衝區類本身的轉換:

var base64data = new Buffer('some binary data', 'binary').toString('base64'); 

console.log(base64data); 
// -> 'c29tZSBiaW5hcnkgZGF0YQ==' 

var originaldata = new Buffer(base64data, 'base64'); 

console.log(originaldata); 
// -> <Buffer 73 6f 6d 65 20 62 69 6e 61 72 79 20 64 61 74 61> 

console.log(originaldata.toString()); 
// -> some binary data