Socket
Socket
Sign inDemoInstall

smart-buffer

Package Overview
Dependencies
0
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.10 to 1.0.11

12

lib/smart-buffer.js

@@ -71,3 +71,3 @@ var SmartBuffer = (function () {

SmartBuffer.prototype._ensureWritable = function (len, offset) {
this._ensureCapacity(this.length + len + (offset || 0));
this._ensureCapacity(this.length + len + (typeof offset === 'number' ? offset : 0));

@@ -77,3 +77,3 @@ if (typeof offset === 'number') {

}
this.length = Math.max(this.length + len, (offset || 0) + len);
this.length = Math.max(this.length + len, (typeof offset === 'number' ? offset : 0) + len);
};

@@ -176,3 +176,3 @@

SmartBuffer.prototype.readBuffer = function (len) {
var endpoint = Math.min(this.length, this._readOffset + (len || this.length));
var endpoint = Math.min(this.length, this._readOffset + (typeof len === 'number' ? len : this.length));
var ret = this.buff.slice(this._readOffset, endpoint);

@@ -277,3 +277,3 @@ this._readOffset = endpoint;

this._ensureWritable(len, offset);
value.copy(this.buff, offset || this._writeOffset);
value.copy(this.buff, typeof offset === 'number' ? offset : this._writeOffset);
this._writeOffset += len;

@@ -292,4 +292,4 @@ return this;

this._ensureWritable(len, offset);
value.copy(this.buff, offset || this._writeOffset);
this.buff[this._writeOffset + len] = 0x00;
value.copy(this.buff, typeof offset === 'number' ? offset : this._writeOffset);
this.buff[(typeof offset === 'number' ? offset : this._writeOffset) + len] = 0x00;
this._writeOffset += len + 1;

@@ -296,0 +296,0 @@ return this;

{
"name": "smart-buffer",
"version": "1.0.10",
"version": "1.0.11",
"description": "A smarter Buffer that keeps track of its own read and write positions while growing endlessly.",

@@ -5,0 +5,0 @@ "main": "lib/smart-buffer.js",

@@ -196,2 +196,29 @@ var SmartBuffer = require('../lib/smart-buffer.js');

describe('Buffer Values', function () {
describe('Writing buffer to position 0', function () {
var buff = new SmartBuffer();
var frontBuff = new Buffer([1, 2, 3, 4, 5, 6]);
buff.writeStringNT('hello');
buff.writeBuffer(frontBuff, 0);
it('should write the buffer to the front of the smart buffer instance', function () {
var readBuff = buff.readBuffer(frontBuff.length);
assert.deepEqual(readBuff, frontBuff);
});
});
describe('Writing null terminated buffer to position 0', function () {
var buff = new SmartBuffer();
var frontBuff = new Buffer([1, 2, 3, 4, 5, 6]);
buff.writeStringNT('hello');
buff.writeBufferNT(frontBuff, 0);
console.log(buff);
it('should write the buffer to the front of the smart buffer instance', function () {
var readBuff = buff.readBufferNT();
console.log(readBuff);
assert.deepEqual(readBuff, frontBuff);
});
});
describe('Explicit lengths', function () {

@@ -240,3 +267,3 @@ var buff = new Buffer([0x01, 0x02, 0x04, 0x08, 0x16, 0x32, 0x64]);

it('Should read the correct null terminated buffer data.', function () {
assert.equal(read1.length, 4);
assert.equal(read1.length, 4);
});

@@ -243,0 +270,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc