Comparing version 0.2.4 to 0.4.0
@@ -6,3 +6,2 @@ /*! | ||
*/ | ||
var util = require(process.binding('natives').util ? 'util': 'sys'); | ||
@@ -15,3 +14,2 @@ /* | ||
var self = this; | ||
process.EventEmitter.call(this);//继承事件类 | ||
var _headLen = 2; | ||
@@ -23,2 +21,4 @@ var _endian = 'B'; | ||
var _dlen = 0; | ||
var slice = Array.prototype.slice; | ||
var _readMethod = 'readUInt16BE'; | ||
@@ -30,2 +30,3 @@ /* | ||
_headLen = 4; | ||
_readMethod = 'readUInt' + (8*_headLen) + ''+ _endian +'E'; | ||
return this; | ||
@@ -39,2 +40,3 @@ }; | ||
_headLen = 2; | ||
_readMethod = 'readUInt' + (8*_headLen) + ''+ _endian +'E'; | ||
return this; | ||
@@ -48,2 +50,3 @@ }; | ||
_endian = 'L'; | ||
_readMethod = 'readUInt' + (8*_headLen) + ''+ _endian +'E'; | ||
return this; | ||
@@ -57,7 +60,56 @@ }; | ||
_endian = 'B'; | ||
_readMethod = 'readUInt' + (8*_headLen) + ''+ _endian +'E'; | ||
return this; | ||
}; | ||
this.once = function(e,cb){ | ||
if(!this.listeners_once)this.listeners_once = {}; | ||
this.listeners_once[e] = this.listeners_once[e] || []; | ||
if(this.listeners_once[e].indexOf(cb) == -1)this.listeners_once[e].push(cb); | ||
}; | ||
this.on = function(e,cb){ | ||
if(!this.listeners)this.listeners = {}; | ||
this.listeners[e] = this.listeners[e] || []; | ||
if(this.listeners[e].indexOf(cb) == -1)this.listeners[e].push(cb); | ||
}; | ||
this.off = function(e,cb){ | ||
var index = -1; | ||
if(this.listeners && this.listeners[e] && (index = this.listeners[e].indexOf(cb)) != -1) | ||
this.listeners[e].splice(index); | ||
}; | ||
this.emit = function(e){ | ||
var other_parameters = slice.call(arguments, 1); | ||
if(this.listeners) { | ||
var list = this.listeners[e]; | ||
if(list) { | ||
for(var i=0;i<list.length;++i) { | ||
// try{ | ||
list[i].apply(this,other_parameters); | ||
// }catch(e){ | ||
// alert(e.stack); | ||
// } | ||
} | ||
} | ||
} | ||
if(this.listeners_once) { | ||
var list = this.listeners_once[e]; | ||
delete this.listeners_once[e]; | ||
if(list) { | ||
for(var i=0;i<list.length;++i) { | ||
// try{ | ||
list[i].apply(this,other_parameters); | ||
// }catch(e){ | ||
// alert(e.stack); | ||
// } | ||
} | ||
} | ||
} | ||
}; | ||
/* | ||
* 送入一端Buffer | ||
* 送入一段Buffer | ||
*/ | ||
@@ -107,6 +159,3 @@ this.put = function(buffer,offset,len){ | ||
} | ||
proc(); | ||
}; | ||
function proc() { | ||
var count = 0; | ||
@@ -124,3 +173,3 @@ while(true){ | ||
if(_buffer.length - _readOffset >= _headLen){ | ||
_dlen = _buffer['readUInt' + (8*_headLen) + ''+ _endian +'E'](_readOffset); | ||
_dlen = _buffer[_readMethod](_readOffset); | ||
_readOffset += _headLen; | ||
@@ -138,3 +187,3 @@ }else {// | ||
} | ||
_dlen = hbuf['readUInt' + (8*_headLen) + ''+ _endian +'E'](0); | ||
_dlen = hbuf[_readMethod](0); | ||
} | ||
@@ -172,3 +221,5 @@ } | ||
} | ||
} | ||
}; | ||
@@ -184,4 +235,2 @@ //获取现在的数据长度 | ||
util.inherits(ExBuffer, process.EventEmitter);//继承事件类 | ||
module.exports = exports = ExBuffer; | ||
@@ -188,0 +237,0 @@ |
@@ -9,3 +9,3 @@ { | ||
"main" : "ExBuffer.js", | ||
"version" : "0.2.4" | ||
"version" : "0.4.0" | ||
} |
@@ -5,2 +5,4 @@ ExBuffer,NodeJs的TCP中的粘包、分包问题的解决方案! | ||
C版本的ExBuffer:https://github.com/play175/exbuffer.c | ||
```javascript | ||
@@ -119,2 +121,2 @@ var ExBuffer = require('./ExBuffer'); | ||
npm install ExBuffer | ||
``` | ||
``` |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
18127
359
121
0