bl 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/bl.js +9 -3
  2. package/package.json +3 -3
  3. package/test/test.js +14 -0
package/bl.js CHANGED
@@ -57,8 +57,14 @@ BufferList.prototype.append = function (buf) {
57
57
  if (typeof buf == 'number')
58
58
  buf = buf.toString()
59
59
 
60
- this._bufs.push(isBuffer ? buf : new Buffer(buf))
61
- this.length += buf.length
60
+ if (buf instanceof BufferList) {
61
+ this._bufs.push.apply(this._bufs, buf._bufs)
62
+ this.length += buf.length
63
+ } else {
64
+ this._bufs.push(isBuffer ? buf : new Buffer(buf))
65
+ this.length += buf.length
66
+ }
67
+
62
68
  return this
63
69
  }
64
70
 
@@ -162,7 +168,7 @@ BufferList.prototype.toString = function (encoding, start, end) {
162
168
 
163
169
  BufferList.prototype.consume = function (bytes) {
164
170
  while (this._bufs.length) {
165
- if (bytes > this._bufs[0].length) {
171
+ if (bytes >= this._bufs[0].length) {
166
172
  bytes -= this._bufs[0].length
167
173
  this.length -= this._bufs[0].length
168
174
  this._bufs.shift()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bl",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too!",
5
5
  "main": "bl.js",
6
6
  "scripts": {
@@ -27,8 +27,8 @@
27
27
  "readable-stream": "~2.0.5"
28
28
  },
29
29
  "devDependencies": {
30
- "tape": "~2.12.3",
30
+ "faucet": "0.0.1",
31
31
  "hash_file": "~0.1.1",
32
- "faucet": "~0.0.1"
32
+ "tape": "~4.4.0"
33
33
  }
34
34
  }
package/test/test.js CHANGED
@@ -128,6 +128,20 @@ tape('consuming from multiple buffers', function (t) {
128
128
  t.end()
129
129
  })
130
130
 
131
+ tape('complete consumption', function (t) {
132
+ var bl = new BufferList()
133
+
134
+ bl.append(new Buffer('a'))
135
+ bl.append(new Buffer('b'))
136
+
137
+ bl.consume(2)
138
+
139
+ t.equal(bl.length, 0)
140
+ t.equal(bl._bufs.length, 0)
141
+
142
+ t.end()
143
+ })
144
+
131
145
  tape('test readUInt8 / readInt8', function (t) {
132
146
  var buf1 = new Buffer(1)
133
147
  , buf2 = new Buffer(3)