Buffer

作者: 我就是L | 来源:发表于2016-11-07 20:08 被阅读4次

    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

    相关文章

      网友评论

          本文标题:Buffer

          本文链接:https://www.haomeiwen.com/subject/pmnluttx.html