Buffer 一段内存缓冲区
申请一段内存
// len:number;
Buffer.alloc(len)
//copy
//
source.copy(target,targetPositionStart,sourcePositionStart,sourcePositionEnd);
// concat
Buffer.concat =function(lists,len = reduce((prev,next)=>prev+next.length,0)){
let buffer =Buffer.alloc(len);
let position =0;
for(let i=0;i<lists.length;i++){
lists[i].copy(buffer,position,0,lists[i].length);
postion +=list[i].length;
}
return buffer.slice(0,position);
}
// split node 当中没有split 方法 只存在indexOf
Buffer.prototype.split=function(sep){
let arr =[];
let position =0;
let len= Buffer.from(sep).length;
let offset =0
// 记录位置
while(-1=(offset = this.indexOf(sep))){
arr.push(this.slice(position,offset));
position =offset + len;
}
arr.push(this.slice(position))
return arr.
}