Buffer

2016-11-07  本文已影响4人  我就是L

var buffer=new Buffer (lenght或字符串数组);

var buffer.write(string,[offest],[lenght],[encoding])在buffer长度范围内写入

buffer中的+=
res.on('data',function(chunk){
buffer+=chunk;//这里的+=会隐式调用buffer.toString(),
})

buffer.setEncoding([encoding])

function concat(list, size) {  
  if (!Array.isArray(list))       
       throw new Error('no a Array');   

 if (size === 0) 
   return Buffer(0);  

 else if (size == 1)
        return list[0];

if (!size || typeof size !== 'number') {       
        var size = 0;       
       for (var i = 0; i < list.length; i++) {
            size += list[i].length;       
     }  
}   
 var buffer = new Buffer(size || length);   
 var pos = 0;    for (var i = 0; i < list.length; i++) { 
       list[i].copy(buffer, pos);    
      pos += list[i].length;
    } 
   return buffer;
}

rs=fs.createReadStream('path/test.txt',{highWaterMark:5})当buffer内容满足highWaterMark时调用data事件,默认8kb

上一篇 下一篇

猜你喜欢

热点阅读