Skip to content

Commit 6a4a26f

Browse files
committed
Add equal check for boundary
1 parent 61dc954 commit 6a4a26f

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ BufferReader.prototype.tell = function() {
2020
};
2121

2222
BufferReader.prototype.seek = function(pos) {
23-
assert(pos > 0 && pos < this.buf.length, 'Position is Invalid');
23+
assert(pos >= 0 && pos <= this.buf.length, 'Position is Invalid');
2424
this.offset = pos;
2525
return this;
2626
};
2727

2828
BufferReader.prototype.move = function(diff) {
29-
assert(this.offset + diff >= 0 && this.offset + diff < this.buf.length, 'Difference is Invalid');
29+
assert(this.offset + diff >= 0 && this.offset + diff <= this.buf.length, 'Difference is Invalid');
3030
this.offset += diff;
3131
return this;
3232
};
@@ -44,7 +44,7 @@ BufferReader.prototype.restAll = function() {
4444

4545
BufferReader.prototype.nextBuffer = function(length) {
4646
assert(length >= 0, 'Length must be no negative');
47-
assert(this.offset + length < this.buf.length, "Out of Original Buffer's Boundary");
47+
assert(this.offset + length <= this.buf.length, "Out of Original Buffer's Boundary");
4848
var buf = new Buffer(length);
4949
this.buf.copy(buf, 0, this.offset, this.offset + length);
5050
this.offset += length;
@@ -53,7 +53,7 @@ BufferReader.prototype.nextBuffer = function(length) {
5353

5454
BufferReader.prototype.nextString = function(length, encoding) {
5555
assert(length >= 0, 'Length must be no negative');
56-
assert(this.offset + length < this.buf.length, "Out of Original Buffer's Boundary");
56+
assert(this.offset + length <= this.buf.length, "Out of Original Buffer's Boundary");
5757

5858
this.offset += length;
5959
return this.buf.toString(encoding || 'utf8', this.offset - length, this.offset);
@@ -63,7 +63,7 @@ BufferReader.prototype.nextString = function(length, encoding) {
6363
function MAKE_NEXT_READER(valueName, size) {
6464
valueName = cap(valueName);
6565
BufferReader.prototype['next' + valueName] = function() {
66-
assert(this.offset + size < this.buf.length, "Out of Original Buffer's Boundary");
66+
assert(this.offset + size <= this.buf.length, "Out of Original Buffer's Boundary");
6767
var val = this.buf['read' + valueName](this.offset);
6868
this.offset += size;
6969
return val;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "buffer-reader",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "a reader for nodejs buffer",
55
"main": "index.js",
66
"scripts": {
@@ -24,4 +24,4 @@
2424
"email": "[email protected]"
2525
},
2626
"license": "BSD"
27-
}
27+
}

0 commit comments

Comments
 (0)