node.js学习(buffer)

创建字符串

var str = "hello noreason";

创建buffer对象,并将str存入缓存

var buf = Buufer.from(str);

创建名为buf2,长度为10的缓存 

 const buf2 = Buffer.alloc(10);

创建名为buf3,长度为10的可能包含敏感数据的缓存

 const buf3 = Buffer.allocUnsafe(10);

创建buf4,转成字符串输出

const buf4 = Buffer.from('我是一串数据');

console.log(buf4.toString()); 

原文地址:https://www.cnblogs.com/noreason/p/10029367.html