const buf = Buffer.from('this is a test!');
//buf的长度
console.log(buf.length);
//如果alloc了一个长度为10的数组呢,并且只定义一个值,那么那么返回的仍然是10
const buf2= Buffer.alloc(10);
buf2[0]=2;
console.log(buf2.length);
//定义多长,就返回多长,与填充的个数无关,用duo少buffer就申请多少buffer
console.log(buf.toString('base64'));
//fill就是向数组里填数
const buf3= Buffer.allocUnsafe(10);
console.log(buf3);
//填写4这个数,从第2个开始填,填到第6个
console.log(buf3.fill(4,2,6));
//equals比较2个buffer的内容是否一样
const buf4= Buffer.from('test');
const buf5= Buffer.from('test');
const buf6= Buffer.from('test!');
console.log(buf4.equals(buf5));
console.log(buf5.equals(buf6));
//indexOf输出索引,如果没有这个字符就输出-1
console.log(buf4.indexOf('es'));
console.log(buf4.indexOf('esa'));