smart-buffer
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -183,2 +183,22 @@ var SmartBuffer = (function () { | ||
/** | ||
* Reads a null terminated sequence of bytes from the underlying buffer. | ||
* @returns {Buffer} Buffer containing the read bytes. | ||
*/ | ||
SmartBuffer.prototype.readBufferNT = function () { | ||
var nullpos = this.length; | ||
for (var i = this._readOffset; i < this.length; i++) { | ||
if (this.buff[i] == 0x00) { | ||
nullpos = i; | ||
break; | ||
} | ||
} | ||
var ret = this.buff.slice(this._readOffset, nullpos); | ||
this._readOffset = nullpos + 1; | ||
return ret; | ||
}; | ||
/* | ||
@@ -185,0 +205,0 @@ Write Operations |
{ | ||
"name": "smart-buffer", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"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", |
@@ -191,2 +191,18 @@ var SmartBuffer = require('../lib/smart-buffer.js'); | ||
describe("Null Terminated Buffer Reading", function () { | ||
var buff = new SmartBuffer(); | ||
buff.writeBuffer(new Buffer([0x01, 0x02, 0x03, 0x04, 0x00, 0x01, 0x02, 0x03])); | ||
var read1 = buff.readBufferNT(); | ||
var read2 = buff.readBufferNT(); | ||
it("Should return a length of 4 for the four bytes before the first null in the buffer.", function () { | ||
assert.equal(read1.length, 4); | ||
}); | ||
it("Should return a length of 3 for the three bytes after the first null in the buffer after reading to end.", function () { | ||
assert.equal(read2.length, 3); | ||
}); | ||
}) | ||
}); | ||
@@ -193,0 +209,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34345
495