码迷,mamicode.com
首页 > 其他好文 > 详细

解析bl源码

时间:2017-05-28 20:52:35      阅读:1648      评论:0      收藏:0      [点我收藏+]

标签:func   this   function   依赖   code   bsp   返回   var   返回值   

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源码

标签:func   this   function   依赖   code   bsp   返回   var   返回值   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!