Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ExBuffer

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ExBuffer - npm Package Compare versions

Comparing version 0.2.4 to 0.4.0

73

ExBuffer.js

@@ -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 @@

2

package.json

@@ -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
```
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc