var sum =0;
for(var i=0;i<8;i++){
sum += Math.pow(2,i);
}
new Buffer(size);
new Buffer(array);
正常情况下为0-255之间;
new Buffer(str,[encoding]);
手动初始化,擦干净桌子,将buffer内容清0
buffer.fill(0);
string, offset, length, encoding
buffer.write('珠',0,3,'utf8');
buffer.write('峰',3,3,'utf8'); //珠峰
将buffer转换成字符串类型 start end 是截取的buffer的长度
buffer.toString('utf8',3,6)
buffer.slice(0,4);
截取乱码问题
var StringDecoder = require('string_decoder').StringDecoder;
var sd = new StringDecoder;
var buffer = new Buffer('珠峰');
console.log(sd.write(buffer.slice(0,4)));
console.log(sd.write(buffer.slice(4)));
复制Buffer 把多个buffer拷贝到一个大buffer上
sourceBuffer.copy(targetBuffer,targetstart,sourcestart,sourceend);
Buffer.concat([buf1,buf2],length);
实现concat方法
判断是否是buffer
Buffer.isBuffer
获取字节长度(显示是字符串所代表buffer的长度)
Buffer.byteLength("珠峰");
buffer.length;
base64的转换