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

bin-protocol

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bin-protocol - npm Package Compare versions

Comparing version 2.0.3 to 2.0.4

8

lib/index.js

@@ -28,5 +28,3 @@ 'use strict';

function Protocol(options) {
this.options = _.defaults(options || {}, {
writerBufSize: 1024,
});
this.options = options || {};
}

@@ -71,4 +69,4 @@

this.reader = new _Reader();
this.writer = new _Writer(this.options.writerBufSize);
this.reader = new _Reader(this.options);
this.writer = new _Writer(this.options);

@@ -75,0 +73,0 @@ if (typeof constructor === 'function') {

@@ -5,6 +5,11 @@ 'use strict';

function Writer(bufferSize) {
function Writer(options) {
var self = this;
self.buffer = new Buffer(bufferSize || 1024);
self.options = _.defaults(options || {}, {
bufferSize: 8 * 1024,
resultCopy: false // set to true if you want write().result to return a copy of the Buffer instead of the slice
});
self.buffer = new Buffer(self.options.bufferSize);
self.offset = 0;

@@ -99,4 +104,10 @@

enumerable: true, get: function () {
var copy;
if (this.options.resultCopy) {
copy = new Buffer(this.offset);
this.buffer.copy(copy, 0, 0, this.offset);
return copy;
}
return this.buffer.slice(0, this.offset);
}
});

@@ -9,3 +9,3 @@ {

},
"version": "2.0.3",
"version": "2.0.4",
"main": "./lib/index.js",

@@ -12,0 +12,0 @@ "keywords": ["buffer", "raw", "binary", "protocol", "parser", "reader", "builder"],

@@ -199,3 +199,3 @@ 'use strict';

var protocol = new Protocol({
writerBufSize: 1
bufferSize: 1
});

@@ -205,2 +205,14 @@ protocol.writer.buffer.length.should.be.eql(1);

});
it('should return a copy of buffer with resultCopy = true', function () {
var protocol = new Protocol({
resultCopy: true
});
var buffer = protocol.write().Int8(1).Int8(2).result;
buffer.should.be.eql(new Buffer([1, 2]));
buffer.writeInt8(10, 0);
buffer.should.be.eql(new Buffer([10, 2]));
protocol.writer.buffer.slice(0, 2).should.be.eql(new Buffer([1, 2]));
});
});
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