Skip to content

Commit

Permalink
Avoid leaving an empty buffer on complete consume
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommy Atkinson authored and rvagg committed Feb 11, 2016
1 parent 9f1e7ce commit 4df2f4c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bl.js
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions test/test.js
Expand Up @@ -125,6 +125,10 @@ tape('consuming from multiple buffers', function (t) {
t.equal(bl.length, 1)
t.equal(bl.slice(0, 1).toString('ascii'), 'j')

bl.consume(1)
t.equal(bl.length, 0)
t.equal(bl._bufs.length, 0)

t.end()
})

Expand Down

0 comments on commit 4df2f4c

Please sign in to comment.