bl 1.1.1 → 1.2.2

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.
package/.travis.yml CHANGED
@@ -4,10 +4,13 @@ node_js:
4
4
  - '0.10'
5
5
  - '0.12'
6
6
  - '4'
7
- - '5'
7
+ - '6'
8
+ - '8'
9
+ - '9'
8
10
  branches:
9
11
  only:
10
12
  - master
11
13
  notifications:
12
14
  email:
13
15
  - rod@vagg.org
16
+ - matteo.collina@gmail.com
package/LICENSE.md CHANGED
@@ -1,7 +1,7 @@
1
1
  The MIT License (MIT)
2
2
  =====================
3
3
 
4
- Copyright (c) 2014 bl contributors
4
+ Copyright (c) 2013-2016 bl contributors
5
5
  ----------------------------------
6
6
 
7
7
  *bl contributors listed at <https://github.com/rvagg/bl#contributors>*
package/README.md CHANGED
@@ -87,6 +87,7 @@ bl.pipe(fs.createWriteStream('gibberish.txt'))
87
87
  * <a href="#append"><code>bl.<b>append(buffer)</b></code></a>
88
88
  * <a href="#get"><code>bl.<b>get(index)</b></code></a>
89
89
  * <a href="#slice"><code>bl.<b>slice([ start[, end ] ])</b></code></a>
90
+ * <a href="#shallowSlice"><code>bl.<b>shallowSlice([ start[, end ] ])</b></code></a>
90
91
  * <a href="#copy"><code>bl.<b>copy(dest, [ destStart, [ srcStart [, srcEnd ] ] ])</b></code></a>
91
92
  * <a href="#duplicate"><code>bl.<b>duplicate()</b></code></a>
92
93
  * <a href="#consume"><code>bl.<b>consume(bytes)</b></code></a>
@@ -107,7 +108,7 @@ Normally, no arguments are required for the constructor, but you can initialise
107
108
  var bl = require('bl')
108
109
  var myinstance = bl()
109
110
 
110
- // equivilant to:
111
+ // equivalent to:
111
112
 
112
113
  var BufferList = require('bl')
113
114
  var myinstance = new BufferList()
@@ -135,6 +136,13 @@ Get the length of the list in bytes. This is the sum of the lengths of all of th
135
136
 
136
137
  If the requested range spans a single internal buffer then a slice of that buffer will be returned which shares the original memory range of that Buffer. If the range spans multiple buffers then copy operations will likely occur to give you a uniform Buffer.
137
138
 
139
+ --------------------------------------------------------
140
+ <a name="shallowSlice"></a>
141
+ ### bl.shallowSlice([ start, [ end ] ])
142
+ `shallowSlice()` returns a new `BufferList` object containing the bytes within the range specified. Both `start` and `end` are optional and will default to the beginning and end of the list respectively.
143
+
144
+ No copies will be performed. All buffers in the result share memory with the original list.
145
+
138
146
  --------------------------------------------------------
139
147
  <a name="copy"></a>
140
148
  ### bl.copy(dest, [ destStart, [ srcStart [, srcEnd ] ] ])
@@ -195,6 +203,6 @@ See the <b><code>[Buffer](http://nodejs.org/docs/latest/api/buffer.html)</code><
195
203
  <a name="license"></a>
196
204
  ## License &amp; copyright
197
205
 
198
- Copyright (c) 2013-2014 bl contributors (listed above).
206
+ Copyright (c) 2013-2016 bl contributors (listed above).
199
207
 
200
208
  bl is licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.
package/bl.js CHANGED
@@ -1,5 +1,7 @@
1
1
  var DuplexStream = require('readable-stream/duplex')
2
2
  , util = require('util')
3
+ , Buffer = require('safe-buffer').Buffer
4
+
3
5
 
4
6
  function BufferList (callback) {
5
7
  if (!(this instanceof BufferList))
@@ -11,17 +13,17 @@ function BufferList (callback) {
11
13
  if (typeof callback == 'function') {
12
14
  this._callback = callback
13
15
 
14
- var piper = function (err) {
16
+ var piper = function piper (err) {
15
17
  if (this._callback) {
16
18
  this._callback(err)
17
19
  this._callback = null
18
20
  }
19
21
  }.bind(this)
20
22
 
21
- this.on('pipe', function (src) {
23
+ this.on('pipe', function onPipe (src) {
22
24
  src.on('error', piper)
23
25
  })
24
- this.on('unpipe', function (src) {
26
+ this.on('unpipe', function onUnpipe (src) {
25
27
  src.removeListener('error', piper)
26
28
  })
27
29
  } else {
@@ -31,23 +33,28 @@ function BufferList (callback) {
31
33
  DuplexStream.call(this)
32
34
  }
33
35
 
36
+
34
37
  util.inherits(BufferList, DuplexStream)
35
38
 
36
- BufferList.prototype._offset = function (offset) {
39
+
40
+ BufferList.prototype._offset = function _offset (offset) {
37
41
  var tot = 0, i = 0, _t
42
+ if (offset === 0) return [ 0, 0 ]
38
43
  for (; i < this._bufs.length; i++) {
39
44
  _t = tot + this._bufs[i].length
40
- if (offset < _t)
45
+ if (offset < _t || i == this._bufs.length - 1)
41
46
  return [ i, offset - tot ]
42
47
  tot = _t
43
48
  }
44
49
  }
45
50
 
46
- BufferList.prototype.append = function (buf) {
51
+
52
+ BufferList.prototype.append = function append (buf) {
47
53
  var i = 0
48
- , newBuf
49
54
 
50
- if (Array.isArray(buf)) {
55
+ if (Buffer.isBuffer(buf)) {
56
+ this._appendBuffer(buf);
57
+ } else if (Array.isArray(buf)) {
51
58
  for (; i < buf.length; i++)
52
59
  this.append(buf[i])
53
60
  } else if (buf instanceof BufferList) {
@@ -60,29 +67,38 @@ BufferList.prototype.append = function (buf) {
60
67
  if (typeof buf == 'number')
61
68
  buf = buf.toString()
62
69
 
63
- newBuf = Buffer.isBuffer(buf) ? buf : new Buffer(buf)
64
- this._bufs.push(newBuf)
65
- this.length += newBuf.length
70
+ this._appendBuffer(Buffer.from(buf));
66
71
  }
67
72
 
68
73
  return this
69
74
  }
70
75
 
71
- BufferList.prototype._write = function (buf, encoding, callback) {
72
- this.append(buf)
73
- if (callback)
76
+
77
+ BufferList.prototype._appendBuffer = function appendBuffer (buf) {
78
+ this._bufs.push(buf)
79
+ this.length += buf.length
80
+ }
81
+
82
+
83
+ BufferList.prototype._write = function _write (buf, encoding, callback) {
84
+ this._appendBuffer(buf)
85
+
86
+ if (typeof callback == 'function')
74
87
  callback()
75
88
  }
76
89
 
77
- BufferList.prototype._read = function (size) {
90
+
91
+ BufferList.prototype._read = function _read (size) {
78
92
  if (!this.length)
79
93
  return this.push(null)
94
+
80
95
  size = Math.min(size, this.length)
81
96
  this.push(this.slice(0, size))
82
97
  this.consume(size)
83
98
  }
84
99
 
85
- BufferList.prototype.end = function (chunk) {
100
+
101
+ BufferList.prototype.end = function end (chunk) {
86
102
  DuplexStream.prototype.end.call(this, chunk)
87
103
 
88
104
  if (this._callback) {
@@ -91,23 +107,30 @@ BufferList.prototype.end = function (chunk) {
91
107
  }
92
108
  }
93
109
 
94
- BufferList.prototype.get = function (index) {
110
+
111
+ BufferList.prototype.get = function get (index) {
95
112
  return this.slice(index, index + 1)[0]
96
113
  }
97
114
 
98
- BufferList.prototype.slice = function (start, end) {
115
+
116
+ BufferList.prototype.slice = function slice (start, end) {
117
+ if (typeof start == 'number' && start < 0)
118
+ start += this.length
119
+ if (typeof end == 'number' && end < 0)
120
+ end += this.length
99
121
  return this.copy(null, 0, start, end)
100
122
  }
101
123
 
102
- BufferList.prototype.copy = function (dst, dstStart, srcStart, srcEnd) {
124
+
125
+ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
103
126
  if (typeof srcStart != 'number' || srcStart < 0)
104
127
  srcStart = 0
105
128
  if (typeof srcEnd != 'number' || srcEnd > this.length)
106
129
  srcEnd = this.length
107
130
  if (srcStart >= this.length)
108
- return dst || new Buffer(0)
131
+ return dst || Buffer.alloc(0)
109
132
  if (srcEnd <= 0)
110
- return dst || new Buffer(0)
133
+ return dst || Buffer.alloc(0)
111
134
 
112
135
  var copy = !!dst
113
136
  , off = this._offset(srcStart)
@@ -120,8 +143,11 @@ BufferList.prototype.copy = function (dst, dstStart, srcStart, srcEnd) {
120
143
 
121
144
  // copy/slice everything
122
145
  if (srcStart === 0 && srcEnd == this.length) {
123
- if (!copy) // slice, just return a full concat
124
- return Buffer.concat(this._bufs)
146
+ if (!copy) { // slice, but full concat if multiple buffers
147
+ return this._bufs.length === 1
148
+ ? this._bufs[0]
149
+ : Buffer.concat(this._bufs, this.length)
150
+ }
125
151
 
126
152
  // copy, need to copy individual buffers
127
153
  for (i = 0; i < this._bufs.length; i++) {
@@ -140,7 +166,7 @@ BufferList.prototype.copy = function (dst, dstStart, srcStart, srcEnd) {
140
166
  }
141
167
 
142
168
  if (!copy) // a slice, we need something to copy in to
143
- dst = new Buffer(len)
169
+ dst = Buffer.allocUnsafe(len)
144
170
 
145
171
  for (i = off[0]; i < this._bufs.length; i++) {
146
172
  l = this._bufs[i].length - start
@@ -162,11 +188,35 @@ BufferList.prototype.copy = function (dst, dstStart, srcStart, srcEnd) {
162
188
  return dst
163
189
  }
164
190
 
165
- BufferList.prototype.toString = function (encoding, start, end) {
191
+ BufferList.prototype.shallowSlice = function shallowSlice (start, end) {
192
+ start = start || 0
193
+ end = end || this.length
194
+
195
+ if (start < 0)
196
+ start += this.length
197
+ if (end < 0)
198
+ end += this.length
199
+
200
+ var startOffset = this._offset(start)
201
+ , endOffset = this._offset(end)
202
+ , buffers = this._bufs.slice(startOffset[0], endOffset[0] + 1)
203
+
204
+ if (endOffset[1] == 0)
205
+ buffers.pop()
206
+ else
207
+ buffers[buffers.length-1] = buffers[buffers.length-1].slice(0, endOffset[1])
208
+
209
+ if (startOffset[1] != 0)
210
+ buffers[0] = buffers[0].slice(startOffset[1])
211
+
212
+ return new BufferList(buffers)
213
+ }
214
+
215
+ BufferList.prototype.toString = function toString (encoding, start, end) {
166
216
  return this.slice(start, end).toString(encoding)
167
217
  }
168
218
 
169
- BufferList.prototype.consume = function (bytes) {
219
+ BufferList.prototype.consume = function consume (bytes) {
170
220
  while (this._bufs.length) {
171
221
  if (bytes >= this._bufs[0].length) {
172
222
  bytes -= this._bufs[0].length
@@ -181,7 +231,8 @@ BufferList.prototype.consume = function (bytes) {
181
231
  return this
182
232
  }
183
233
 
184
- BufferList.prototype.duplicate = function () {
234
+
235
+ BufferList.prototype.duplicate = function duplicate () {
185
236
  var i = 0
186
237
  , copy = new BufferList()
187
238
 
@@ -191,12 +242,14 @@ BufferList.prototype.duplicate = function () {
191
242
  return copy
192
243
  }
193
244
 
194
- BufferList.prototype.destroy = function () {
195
- this._bufs.length = 0;
196
- this.length = 0;
197
- this.push(null);
245
+
246
+ BufferList.prototype.destroy = function destroy () {
247
+ this._bufs.length = 0
248
+ this.length = 0
249
+ this.push(null)
198
250
  }
199
251
 
252
+
200
253
  ;(function () {
201
254
  var methods = {
202
255
  'readDoubleBE' : 8
@@ -224,4 +277,5 @@ BufferList.prototype.destroy = function () {
224
277
  }
225
278
  }())
226
279
 
280
+
227
281
  module.exports = BufferList
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bl",
3
- "version": "1.1.1",
3
+ "version": "1.2.2",
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": {
@@ -24,11 +24,12 @@
24
24
  ],
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
- "readable-stream": "~2.0.5"
27
+ "readable-stream": "^2.3.5",
28
+ "safe-buffer": "^5.1.1"
28
29
  },
29
30
  "devDependencies": {
30
31
  "faucet": "0.0.1",
31
32
  "hash_file": "~0.1.1",
32
- "tape": "~4.4.0"
33
+ "tape": "~4.9.0"
33
34
  }
34
35
  }
package/test/test.js CHANGED
@@ -3,6 +3,7 @@ var tape = require('tape')
3
3
  , fs = require('fs')
4
4
  , hash = require('hash_file')
5
5
  , BufferList = require('../')
6
+ , Buffer = require('safe-buffer').Buffer
6
7
 
7
8
  , encodings =
8
9
  ('hex utf8 utf-8 ascii binary base64'
@@ -10,7 +11,7 @@ var tape = require('tape')
10
11
 
11
12
  tape('single bytes from single buffer', function (t) {
12
13
  var bl = new BufferList()
13
- bl.append(new Buffer('abcd'))
14
+ bl.append(Buffer.from('abcd'))
14
15
 
15
16
  t.equal(bl.length, 4)
16
17
 
@@ -24,10 +25,10 @@ tape('single bytes from single buffer', function (t) {
24
25
 
25
26
  tape('single bytes from multiple buffers', function (t) {
26
27
  var bl = new BufferList()
27
- bl.append(new Buffer('abcd'))
28
- bl.append(new Buffer('efg'))
29
- bl.append(new Buffer('hi'))
30
- bl.append(new Buffer('j'))
28
+ bl.append(Buffer.from('abcd'))
29
+ bl.append(Buffer.from('efg'))
30
+ bl.append(Buffer.from('hi'))
31
+ bl.append(Buffer.from('j'))
31
32
 
32
33
  t.equal(bl.length, 10)
33
34
 
@@ -46,13 +47,27 @@ tape('single bytes from multiple buffers', function (t) {
46
47
 
47
48
  tape('multi bytes from single buffer', function (t) {
48
49
  var bl = new BufferList()
49
- bl.append(new Buffer('abcd'))
50
+ bl.append(Buffer.from('abcd'))
50
51
 
51
52
  t.equal(bl.length, 4)
52
53
 
53
54
  t.equal(bl.slice(0, 4).toString('ascii'), 'abcd')
54
55
  t.equal(bl.slice(0, 3).toString('ascii'), 'abc')
55
56
  t.equal(bl.slice(1, 4).toString('ascii'), 'bcd')
57
+ t.equal(bl.slice(-4, -1).toString('ascii'), 'abc')
58
+
59
+ t.end()
60
+ })
61
+
62
+ tape('multi bytes from single buffer (negative indexes)', function (t) {
63
+ var bl = new BufferList()
64
+ bl.append(Buffer.from('buffer'))
65
+
66
+ t.equal(bl.length, 6)
67
+
68
+ t.equal(bl.slice(-6, -1).toString('ascii'), 'buffe')
69
+ t.equal(bl.slice(-6, -2).toString('ascii'), 'buff')
70
+ t.equal(bl.slice(-5, -2).toString('ascii'), 'uff')
56
71
 
57
72
  t.end()
58
73
  })
@@ -60,10 +75,10 @@ tape('multi bytes from single buffer', function (t) {
60
75
  tape('multiple bytes from multiple buffers', function (t) {
61
76
  var bl = new BufferList()
62
77
 
63
- bl.append(new Buffer('abcd'))
64
- bl.append(new Buffer('efg'))
65
- bl.append(new Buffer('hi'))
66
- bl.append(new Buffer('j'))
78
+ bl.append(Buffer.from('abcd'))
79
+ bl.append(Buffer.from('efg'))
80
+ bl.append(Buffer.from('hi'))
81
+ bl.append(Buffer.from('j'))
67
82
 
68
83
  t.equal(bl.length, 10)
69
84
 
@@ -72,6 +87,7 @@ tape('multiple bytes from multiple buffers', function (t) {
72
87
  t.equal(bl.slice(3, 6).toString('ascii'), 'def')
73
88
  t.equal(bl.slice(3, 8).toString('ascii'), 'defgh')
74
89
  t.equal(bl.slice(5, 10).toString('ascii'), 'fghij')
90
+ t.equal(bl.slice(-7, -4).toString('ascii'), 'def')
75
91
 
76
92
  t.end()
77
93
  })
@@ -79,8 +95,8 @@ tape('multiple bytes from multiple buffers', function (t) {
79
95
  tape('multiple bytes from multiple buffer lists', function (t) {
80
96
  var bl = new BufferList()
81
97
 
82
- bl.append(new BufferList([ new Buffer('abcd'), new Buffer('efg') ]))
83
- bl.append(new BufferList([ new Buffer('hi'), new Buffer('j') ]))
98
+ bl.append(new BufferList([ Buffer.from('abcd'), Buffer.from('efg') ]))
99
+ bl.append(new BufferList([ Buffer.from('hi'), Buffer.from('j') ]))
84
100
 
85
101
  t.equal(bl.length, 10)
86
102
 
@@ -100,12 +116,12 @@ tape('multiple bytes from crazy nested buffer lists', function (t) {
100
116
 
101
117
  bl.append(new BufferList([
102
118
  new BufferList([
103
- new BufferList(new Buffer('abc'))
104
- , new Buffer('d')
105
- , new BufferList(new Buffer('efg'))
119
+ new BufferList(Buffer.from('abc'))
120
+ , Buffer.from('d')
121
+ , new BufferList(Buffer.from('efg'))
106
122
  ])
107
- , new BufferList([ new Buffer('hi') ])
108
- , new BufferList(new Buffer('j'))
123
+ , new BufferList([ Buffer.from('hi') ])
124
+ , new BufferList(Buffer.from('j'))
109
125
  ]))
110
126
 
111
127
  t.equal(bl.length, 10)
@@ -122,10 +138,10 @@ tape('multiple bytes from crazy nested buffer lists', function (t) {
122
138
 
123
139
  tape('append accepts arrays of Buffers', function (t) {
124
140
  var bl = new BufferList()
125
- bl.append(new Buffer('abc'))
126
- bl.append([ new Buffer('def') ])
127
- bl.append([ new Buffer('ghi'), new Buffer('jkl') ])
128
- bl.append([ new Buffer('mnop'), new Buffer('qrstu'), new Buffer('vwxyz') ])
141
+ bl.append(Buffer.from('abc'))
142
+ bl.append([ Buffer.from('def') ])
143
+ bl.append([ Buffer.from('ghi'), Buffer.from('jkl') ])
144
+ bl.append([ Buffer.from('mnop'), Buffer.from('qrstu'), Buffer.from('vwxyz') ])
129
145
  t.equal(bl.length, 26)
130
146
  t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
131
147
  t.end()
@@ -133,10 +149,10 @@ tape('append accepts arrays of Buffers', function (t) {
133
149
 
134
150
  tape('append accepts arrays of BufferLists', function (t) {
135
151
  var bl = new BufferList()
136
- bl.append(new Buffer('abc'))
152
+ bl.append(Buffer.from('abc'))
137
153
  bl.append([ new BufferList('def') ])
138
- bl.append(new BufferList([ new Buffer('ghi'), new BufferList('jkl') ]))
139
- bl.append([ new Buffer('mnop'), new BufferList([ new Buffer('qrstu'), new Buffer('vwxyz') ]) ])
154
+ bl.append(new BufferList([ Buffer.from('ghi'), new BufferList('jkl') ]))
155
+ bl.append([ Buffer.from('mnop'), new BufferList([ Buffer.from('qrstu'), Buffer.from('vwxyz') ]) ])
140
156
  t.equal(bl.length, 26)
141
157
  t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
142
158
  t.end()
@@ -144,18 +160,18 @@ tape('append accepts arrays of BufferLists', function (t) {
144
160
 
145
161
  tape('append chainable', function (t) {
146
162
  var bl = new BufferList()
147
- t.ok(bl.append(new Buffer('abcd')) === bl)
148
- t.ok(bl.append([ new Buffer('abcd') ]) === bl)
149
- t.ok(bl.append(new BufferList(new Buffer('abcd'))) === bl)
150
- t.ok(bl.append([ new BufferList(new Buffer('abcd')) ]) === bl)
163
+ t.ok(bl.append(Buffer.from('abcd')) === bl)
164
+ t.ok(bl.append([ Buffer.from('abcd') ]) === bl)
165
+ t.ok(bl.append(new BufferList(Buffer.from('abcd'))) === bl)
166
+ t.ok(bl.append([ new BufferList(Buffer.from('abcd')) ]) === bl)
151
167
  t.end()
152
168
  })
153
169
 
154
170
  tape('append chainable (test results)', function (t) {
155
171
  var bl = new BufferList('abc')
156
172
  .append([ new BufferList('def') ])
157
- .append(new BufferList([ new Buffer('ghi'), new BufferList('jkl') ]))
158
- .append([ new Buffer('mnop'), new BufferList([ new Buffer('qrstu'), new Buffer('vwxyz') ]) ])
173
+ .append(new BufferList([ Buffer.from('ghi'), new BufferList('jkl') ]))
174
+ .append([ Buffer.from('mnop'), new BufferList([ Buffer.from('qrstu'), Buffer.from('vwxyz') ]) ])
159
175
 
160
176
  t.equal(bl.length, 26)
161
177
  t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
@@ -165,10 +181,10 @@ tape('append chainable (test results)', function (t) {
165
181
  tape('consuming from multiple buffers', function (t) {
166
182
  var bl = new BufferList()
167
183
 
168
- bl.append(new Buffer('abcd'))
169
- bl.append(new Buffer('efg'))
170
- bl.append(new Buffer('hi'))
171
- bl.append(new Buffer('j'))
184
+ bl.append(Buffer.from('abcd'))
185
+ bl.append(Buffer.from('efg'))
186
+ bl.append(Buffer.from('hi'))
187
+ bl.append(Buffer.from('j'))
172
188
 
173
189
  t.equal(bl.length, 10)
174
190
 
@@ -200,8 +216,8 @@ tape('consuming from multiple buffers', function (t) {
200
216
  tape('complete consumption', function (t) {
201
217
  var bl = new BufferList()
202
218
 
203
- bl.append(new Buffer('a'))
204
- bl.append(new Buffer('b'))
219
+ bl.append(Buffer.from('a'))
220
+ bl.append(Buffer.from('b'))
205
221
 
206
222
  bl.consume(2)
207
223
 
@@ -212,9 +228,9 @@ tape('complete consumption', function (t) {
212
228
  })
213
229
 
214
230
  tape('test readUInt8 / readInt8', function (t) {
215
- var buf1 = new Buffer(1)
216
- , buf2 = new Buffer(3)
217
- , buf3 = new Buffer(3)
231
+ var buf1 = Buffer.alloc(1)
232
+ , buf2 = Buffer.alloc(3)
233
+ , buf3 = Buffer.alloc(3)
218
234
  , bl = new BufferList()
219
235
 
220
236
  buf2[1] = 0x3
@@ -238,9 +254,9 @@ tape('test readUInt8 / readInt8', function (t) {
238
254
  })
239
255
 
240
256
  tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t) {
241
- var buf1 = new Buffer(1)
242
- , buf2 = new Buffer(3)
243
- , buf3 = new Buffer(3)
257
+ var buf1 = Buffer.alloc(1)
258
+ , buf2 = Buffer.alloc(3)
259
+ , buf3 = Buffer.alloc(3)
244
260
  , bl = new BufferList()
245
261
 
246
262
  buf2[1] = 0x3
@@ -268,9 +284,9 @@ tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t
268
284
  })
269
285
 
270
286
  tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t) {
271
- var buf1 = new Buffer(1)
272
- , buf2 = new Buffer(3)
273
- , buf3 = new Buffer(3)
287
+ var buf1 = Buffer.alloc(1)
288
+ , buf2 = Buffer.alloc(3)
289
+ , buf3 = Buffer.alloc(3)
274
290
  , bl = new BufferList()
275
291
 
276
292
  buf2[1] = 0x3
@@ -290,9 +306,9 @@ tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t
290
306
  })
291
307
 
292
308
  tape('test readFloatLE / readFloatBE', function (t) {
293
- var buf1 = new Buffer(1)
294
- , buf2 = new Buffer(3)
295
- , buf3 = new Buffer(3)
309
+ var buf1 = Buffer.alloc(1)
310
+ , buf2 = Buffer.alloc(3)
311
+ , buf3 = Buffer.alloc(3)
296
312
  , bl = new BufferList()
297
313
 
298
314
  buf2[1] = 0x00
@@ -309,9 +325,9 @@ tape('test readFloatLE / readFloatBE', function (t) {
309
325
  })
310
326
 
311
327
  tape('test readDoubleLE / readDoubleBE', function (t) {
312
- var buf1 = new Buffer(1)
313
- , buf2 = new Buffer(3)
314
- , buf3 = new Buffer(10)
328
+ var buf1 = Buffer.alloc(1)
329
+ , buf2 = Buffer.alloc(3)
330
+ , buf3 = Buffer.alloc(10)
315
331
  , bl = new BufferList()
316
332
 
317
333
  buf2[1] = 0x55
@@ -334,10 +350,10 @@ tape('test readDoubleLE / readDoubleBE', function (t) {
334
350
  tape('test toString', function (t) {
335
351
  var bl = new BufferList()
336
352
 
337
- bl.append(new Buffer('abcd'))
338
- bl.append(new Buffer('efg'))
339
- bl.append(new Buffer('hi'))
340
- bl.append(new Buffer('j'))
353
+ bl.append(Buffer.from('abcd'))
354
+ bl.append(Buffer.from('efg'))
355
+ bl.append(Buffer.from('hi'))
356
+ bl.append(Buffer.from('j'))
341
357
 
342
358
  t.equal(bl.toString('ascii', 0, 10), 'abcdefghij')
343
359
  t.equal(bl.toString('ascii', 3, 10), 'defghij')
@@ -350,13 +366,13 @@ tape('test toString', function (t) {
350
366
 
351
367
  tape('test toString encoding', function (t) {
352
368
  var bl = new BufferList()
353
- , b = new Buffer('abcdefghij\xff\x00')
369
+ , b = Buffer.from('abcdefghij\xff\x00')
354
370
 
355
- bl.append(new Buffer('abcd'))
356
- bl.append(new Buffer('efg'))
357
- bl.append(new Buffer('hi'))
358
- bl.append(new Buffer('j'))
359
- bl.append(new Buffer('\xff\x00'))
371
+ bl.append(Buffer.from('abcd'))
372
+ bl.append(Buffer.from('efg'))
373
+ bl.append(Buffer.from('hi'))
374
+ bl.append(Buffer.from('j'))
375
+ bl.append(Buffer.from('\xff\x00'))
360
376
 
361
377
  encodings.forEach(function (enc) {
362
378
  t.equal(bl.toString(enc), b.toString(enc), enc)
@@ -404,7 +420,7 @@ tape('instantiation with Buffer', function (t) {
404
420
 
405
421
  tape('test String appendage', function (t) {
406
422
  var bl = new BufferList()
407
- , b = new Buffer('abcdefghij\xff\x00')
423
+ , b = Buffer.from('abcdefghij\xff\x00')
408
424
 
409
425
  bl.append('abcd')
410
426
  bl.append('efg')
@@ -421,7 +437,7 @@ tape('test String appendage', function (t) {
421
437
 
422
438
  tape('test Number appendage', function (t) {
423
439
  var bl = new BufferList()
424
- , b = new Buffer('1234567890')
440
+ , b = Buffer.from('1234567890')
425
441
 
426
442
  bl.append(1234)
427
443
  bl.append(567)
@@ -455,7 +471,7 @@ tape('unicode string', function (t) {
455
471
  bl.write(' and ')
456
472
  bl.write(inp2)
457
473
  t.equal(exp, bl.toString())
458
- t.equal(new Buffer(exp).toString('hex'), bl.toString('hex'))
474
+ t.equal(Buffer.from(exp).toString('hex'), bl.toString('hex'))
459
475
  })
460
476
 
461
477
  tape('should emit finish', function (t) {
@@ -473,7 +489,7 @@ tape('should emit finish', function (t) {
473
489
 
474
490
  tape('basic copy', function (t) {
475
491
  var buf = crypto.randomBytes(1024)
476
- , buf2 = new Buffer(1024)
492
+ , buf2 = Buffer.alloc(1024)
477
493
  , b = BufferList(buf)
478
494
 
479
495
  b.copy(buf2)
@@ -483,7 +499,7 @@ tape('basic copy', function (t) {
483
499
 
484
500
  tape('copy after many appends', function (t) {
485
501
  var buf = crypto.randomBytes(512)
486
- , buf2 = new Buffer(1024)
502
+ , buf2 = Buffer.alloc(1024)
487
503
  , b = BufferList(buf)
488
504
 
489
505
  b.append(buf)
@@ -494,7 +510,7 @@ tape('copy after many appends', function (t) {
494
510
 
495
511
  tape('copy at a precise position', function (t) {
496
512
  var buf = crypto.randomBytes(1004)
497
- , buf2 = new Buffer(1024)
513
+ , buf2 = Buffer.alloc(1024)
498
514
  , b = BufferList(buf)
499
515
 
500
516
  b.copy(buf2, 20)
@@ -504,7 +520,7 @@ tape('copy at a precise position', function (t) {
504
520
 
505
521
  tape('copy starting from a precise location', function (t) {
506
522
  var buf = crypto.randomBytes(10)
507
- , buf2 = new Buffer(5)
523
+ , buf2 = Buffer.alloc(5)
508
524
  , b = BufferList(buf)
509
525
 
510
526
  b.copy(buf2, 0, 5)
@@ -515,8 +531,8 @@ tape('copy starting from a precise location', function (t) {
515
531
  tape('copy in an interval', function (t) {
516
532
  var rnd = crypto.randomBytes(10)
517
533
  , b = BufferList(rnd) // put the random bytes there
518
- , actual = new Buffer(3)
519
- , expected = new Buffer(3)
534
+ , actual = Buffer.alloc(3)
535
+ , expected = Buffer.alloc(3)
520
536
 
521
537
  rnd.copy(expected, 0, 5, 8)
522
538
  b.copy(actual, 0, 5, 8)
@@ -527,7 +543,7 @@ tape('copy in an interval', function (t) {
527
543
 
528
544
  tape('copy an interval between two buffers', function (t) {
529
545
  var buf = crypto.randomBytes(10)
530
- , buf2 = new Buffer(10)
546
+ , buf2 = Buffer.alloc(10)
531
547
  , b = BufferList(buf)
532
548
 
533
549
  b.append(buf)
@@ -537,6 +553,52 @@ tape('copy an interval between two buffers', function (t) {
537
553
  t.end()
538
554
  })
539
555
 
556
+ tape('shallow slice across buffer boundaries', function (t) {
557
+ var bl = new BufferList(['First', 'Second', 'Third'])
558
+
559
+ t.equal(bl.shallowSlice(3, 13).toString(), 'stSecondTh')
560
+ t.end()
561
+ })
562
+
563
+ tape('shallow slice within single buffer', function (t) {
564
+ t.plan(2)
565
+ var bl = new BufferList(['First', 'Second', 'Third'])
566
+
567
+ t.equal(bl.shallowSlice(5, 10).toString(), 'Secon')
568
+ t.equal(bl.shallowSlice(7, 10).toString(), 'con')
569
+ t.end()
570
+ })
571
+
572
+ tape('shallow slice single buffer', function (t) {
573
+ t.plan(3)
574
+ var bl = new BufferList(['First', 'Second', 'Third'])
575
+
576
+ t.equal(bl.shallowSlice(0, 5).toString(), 'First')
577
+ t.equal(bl.shallowSlice(5, 11).toString(), 'Second')
578
+ t.equal(bl.shallowSlice(11, 16).toString(), 'Third')
579
+ })
580
+
581
+ tape('shallow slice with negative or omitted indices', function (t) {
582
+ t.plan(4)
583
+ var bl = new BufferList(['First', 'Second', 'Third'])
584
+
585
+ t.equal(bl.shallowSlice().toString(), 'FirstSecondThird')
586
+ t.equal(bl.shallowSlice(5).toString(), 'SecondThird')
587
+ t.equal(bl.shallowSlice(5, -3).toString(), 'SecondTh')
588
+ t.equal(bl.shallowSlice(-8).toString(), 'ondThird')
589
+ })
590
+
591
+ tape('shallow slice does not make a copy', function (t) {
592
+ t.plan(1)
593
+ var buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
594
+ var bl = (new BufferList(buffers)).shallowSlice(5, -3)
595
+
596
+ buffers[1].fill('h')
597
+ buffers[2].fill('h')
598
+
599
+ t.equal(bl.toString(), 'hhhhhhhh')
600
+ })
601
+
540
602
  tape('duplicate', function (t) {
541
603
  t.plan(2)
542
604
 
package/.npmignore DELETED
@@ -1 +0,0 @@
1
- node_modules/