首页 > 其他 > 详细

解析bl源码

时间:2017-05-28 20:48:42      阅读:926      评论:0      收藏:0      [点我收藏+]

1.声明依赖

/*
   Duplex 流是同时实现了 Readable 和 Writable 接口的流。
   而且Duplex类的实例包括了TCP socket、zlib streams和ctypto.streams
*/
var DuplexStream = require(‘readable-stream/duplex‘)

2.及时函数

(function () {
  var methods = {
      ‘readDoubleBE‘ : 8
    , ‘readDoubleLE‘ : 8
    , ‘readFloatBE‘  : 4
    , ‘readFloatLE‘  : 4
    , ‘readInt32BE‘  : 4
    , ‘readInt32LE‘  : 4
    , ‘readUInt32BE‘ : 4
    , ‘readUInt32LE‘ : 4
    , ‘readInt16BE‘  : 2
    , ‘readInt16LE‘  : 2
    , ‘readUInt16BE‘ : 2
    , ‘readUInt16LE‘ : 2
    , ‘readInt8‘     : 1
    , ‘readUInt8‘    : 1
  }

  for (var m in methods) {
    (function (m) {
      BufferList.prototype[m] = function (offset) {
        //把methods[m]闭包。提供BufferList的实例的方法,该方法有返回值。
        return this.slice(offset, offset + methods[m])[m](0)
      }
    }(m))
  }
}());

 

解析bl源码

原文:http://www.cnblogs.com/liuyinlei/p/6916542.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!