Buffer.from(str[, encoding])
Node.js FS模塊方法速查
- str {String} 需要編碼的字符串
- encoding {String} 編碼時用到,默認:'utf8'
const buf2 = Buffer.from('7468697320697320612074c3a97374', 'hex');
console.log(buf2.toString());
// prints: this is a tést
如果 str 不是一個有效的 String 則拋出一個 TypeError 錯誤。