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.5 to 1.0.6

test/smart-buffer.test.js

37

lib/smart-buffer.js

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

switch (type = typeof arg1) {
case "number":
case 'number':
if (isFinite(arg1) && arg1 > 0) {

@@ -27,7 +27,7 @@ this.buff = new Buffer(Math.ceil(arg1));

} else {
throw new Error("When specifying a size, it must be a valid number above zero.");
throw new Error('When specifying a size, it must be a valid number above zero.');
}
break;
case "string":
case 'string':
if (Buffer.isEncoding(arg1)) {

@@ -38,7 +38,7 @@ this.buff = new Buffer(4096);

} else {
throw new Error("Invalid Encoding");
throw new Error('Invalid Encoding');
}
break;
case "object":
case 'object':
if (Buffer.isBuffer(arg1)) {

@@ -48,21 +48,18 @@ this.buff = arg1;

} else {
throw new TypeError("First argument must be a Buffer, Number representing the size, or a String representing the encoding.");
throw new TypeError('First argument must be a Buffer, Number representing the size, or a String representing the encoding.');
}
break;
case "undefined":
default:
this.buff = new Buffer(4096);
this.length = 0;
break;
default:
throw new TypeError("First argument must be a Buffer, Number representing the size, or a String representing the encoding.");
}
if (typeof this.encoding === "undefined") {
if (typeof arg2 === "string") {
if (typeof this.encoding === 'undefined') {
if (typeof arg2 === 'string') {
if (Buffer.isEncoding(arg2)) {
this.encoding = arg2;
} else {
throw new Error("Invalid Encoding");
throw new Error('Invalid Encoding');
}

@@ -80,3 +77,3 @@ }

if (typeof offset === "number") {
if (typeof offset === 'number') {
this.buff.copy(this.buff, offset + len, offset, this.buff.length);

@@ -112,3 +109,3 @@ }

this._ensureWritable(size, offset);
func.call(this.buff, value, typeof offset === "number" ? offset : this._writeOffset);
func.call(this.buff, value, typeof offset === 'number' ? offset : this._writeOffset);
this._writeOffset += size;

@@ -243,5 +240,5 @@ return this;

if (type === "number") {
if (type === 'number') {
_offset = offset;
} else if (type === "string") {
} else if (type === 'string') {
encoding = offset;

@@ -313,3 +310,3 @@ offset = this._writeOffset;

if (this._readOffset + amount > this.length)
throw new Error("Target position is beyond the bounds of the data.");
throw new Error('Target position is beyond the bounds of the data.');

@@ -325,3 +322,3 @@ this._readOffset += amount;

if (this._readOffset - amount < 0)
throw new Error("Target position is beyond the bounds of the data.");
throw new Error('Target position is beyond the bounds of the data.');

@@ -337,3 +334,3 @@ this._readOffset -= amount;

if (position < 0 || position > this.length)
throw new Error("Target position is beyond the bounds of the data.");
throw new Error('Target position is beyond the bounds of the data.');

@@ -340,0 +337,0 @@ this._readOffset = position;

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

@@ -17,8 +17,7 @@ "main": "lib/smart-buffer.js",

"smart",
"cursor",
"simple",
"serialize",
"packet",
"network",
"null terminated",
"growing"
"cursor",
"simple"
],

@@ -34,10 +33,13 @@ "engines": {

"chai": "^2.2.0",
"mocha": "^2.2.3"
"coveralls": "^2.11.9",
"istanbul": "^0.4.3",
"mocha": "^2.2.3",
"mocha-lcov-reporter": "^1.2.0"
},
"dependencies": {
},
"dependencies": {},
"scripts": {
"test": "mocha test/test.js"
"test": "mocha test/smart-buffer.test.js",
"coverage": "istanbul cover node_modules/mocha/bin/_mocha recursive test",
"fullcoverage": "node_modules/.bin/istanbul -include-all-sources cover node_modules/mocha/bin/_mocha recursive test"
}
}

@@ -1,2 +0,2 @@

smart-buffer [![Build Status](https://travis-ci.org/JoshGlazebrook/smart-buffer.svg?branch=master)](https://travis-ci.org/JoshGlazebrook/smart-buffer)
smart-buffer [![Build Status](https://travis-ci.org/JoshGlazebrook/smart-buffer.svg?branch=master)](https://travis-ci.org/JoshGlazebrook/smart-buffer) [![Coverage Status](https://coveralls.io/repos/github/JoshGlazebrook/smart-buffer/badge.svg?branch=master)](https://coveralls.io/github/JoshGlazebrook/smart-buffer?branch=master)
=============

@@ -165,2 +165,10 @@

### SmartBuffer.readBufferNT()
returns `Buffer`
> Note: This reads the next sequence of bytes in the buffer until a null (0x00) value is found. (Null terminated buffer)
> Note: This function uses `slice` to retrieve the Buffer.
## Writing Data

@@ -167,0 +175,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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