smart-buffer
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -156,3 +156,3 @@ var SmartBuffer = (function () { | ||
SmartBuffer.prototype.readStringNT = function (encoding) { | ||
var nullpos = this.length - 1; | ||
var nullpos = this.length; | ||
for (var i = this._readOffset; i < this.length; i++) { | ||
@@ -164,2 +164,3 @@ if (this.buff[i] == 0x00) { | ||
} | ||
var result = this.buff.slice(this._readOffset, nullpos); | ||
@@ -166,0 +167,0 @@ this._readOffset = nullpos + 1; |
{ | ||
"name": "smart-buffer", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"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", |
@@ -147,2 +147,25 @@ var SmartBuffer = require('../lib/smart-buffer.js'); | ||
describe("Null/non-null terminating strings", function () { | ||
var reader = new SmartBuffer(); | ||
reader.writeString("hello\0test\0bleh"); | ||
it("should equal hello", function() { | ||
assert.strictEqual(reader.readStringNT(), "hello"); | ||
}); | ||
it("should equal: test", function() { | ||
assert.strictEqual(reader.readString(4), "test"); | ||
}); | ||
it("should have a length of zero", function() { | ||
assert.strictEqual(reader.readStringNT().length, 0); | ||
}); | ||
it("should equal: bleh", function () { | ||
assert.strictEqual(reader.readStringNT(), "bleh"); | ||
}); | ||
}); | ||
describe("Buffer Values", function () { | ||
@@ -149,0 +172,0 @@ var buff = new Buffer([0x01, 0x02, 0x04, 0x08, 0x16, 0x32, 0x64]); |
32410
457