diff --git a/bl.js b/bl.js index b979ba8..f0232e4 100644 --- a/bl.js +++ b/bl.js @@ -162,7 +162,7 @@ BufferList.prototype.toString = function (encoding, start, end) { BufferList.prototype.consume = function (bytes) { while (this._bufs.length) { - if (bytes > this._bufs[0].length) { + if (bytes >= this._bufs[0].length) { bytes -= this._bufs[0].length this.length -= this._bufs[0].length this._bufs.shift() diff --git a/test/test.js b/test/test.js index 8c8d0cf..2f0c6d3 100644 --- a/test/test.js +++ b/test/test.js @@ -128,6 +128,20 @@ tape('consuming from multiple buffers', function (t) { t.end() }) +tape('complete consumption', function (t) { + var bl = new BufferList() + + bl.append(new Buffer('a')) + bl.append(new Buffer('b')) + + bl.consume(2) + + t.equal(bl.length, 0) + t.equal(bl._bufs.length, 0) + + t.end() +}) + tape('test readUInt8 / readInt8', function (t) { var buf1 = new Buffer(1) , buf2 = new Buffer(3)