bl 1.2.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
@@ -5,7 +5,8 @@ node_js:
5
5
  - '0.12'
6
6
  - '4'
7
7
  - '6'
8
- - '7'
8
+ - '8'
9
+ - '9'
9
10
  branches:
10
11
  only:
11
12
  - master
package/README.md CHANGED
@@ -108,7 +108,7 @@ Normally, no arguments are required for the constructor, but you can initialise
108
108
  var bl = require('bl')
109
109
  var myinstance = bl()
110
110
 
111
- // equivilant to:
111
+ // equivalent to:
112
112
 
113
113
  var BufferList = require('bl')
114
114
  var myinstance = new BufferList()
package/bl.js CHANGED
@@ -1,5 +1,6 @@
1
1
  var DuplexStream = require('readable-stream/duplex')
2
2
  , util = require('util')
3
+ , Buffer = require('safe-buffer').Buffer
3
4
 
4
5
 
5
6
  function BufferList (callback) {
@@ -66,7 +67,7 @@ BufferList.prototype.append = function append (buf) {
66
67
  if (typeof buf == 'number')
67
68
  buf = buf.toString()
68
69
 
69
- this._appendBuffer(new Buffer(buf));
70
+ this._appendBuffer(Buffer.from(buf));
70
71
  }
71
72
 
72
73
  return this
@@ -127,9 +128,9 @@ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
127
128
  if (typeof srcEnd != 'number' || srcEnd > this.length)
128
129
  srcEnd = this.length
129
130
  if (srcStart >= this.length)
130
- return dst || new Buffer(0)
131
+ return dst || Buffer.alloc(0)
131
132
  if (srcEnd <= 0)
132
- return dst || new Buffer(0)
133
+ return dst || Buffer.alloc(0)
133
134
 
134
135
  var copy = !!dst
135
136
  , off = this._offset(srcStart)
@@ -165,7 +166,7 @@ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
165
166
  }
166
167
 
167
168
  if (!copy) // a slice, we need something to copy in to
168
- dst = new Buffer(len)
169
+ dst = Buffer.allocUnsafe(len)
169
170
 
170
171
  for (i = off[0]; i < this._bufs.length; i++) {
171
172
  l = this._bufs[i].length - start
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bl",
3
- "version": "1.2.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.6.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,7 +47,7 @@ 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
 
@@ -60,7 +61,7 @@ tape('multi bytes from single buffer', function (t) {
60
61
 
61
62
  tape('multi bytes from single buffer (negative indexes)', function (t) {
62
63
  var bl = new BufferList()
63
- bl.append(new Buffer('buffer'))
64
+ bl.append(Buffer.from('buffer'))
64
65
 
65
66
  t.equal(bl.length, 6)
66
67
 
@@ -74,10 +75,10 @@ tape('multi bytes from single buffer (negative indexes)', function (t) {
74
75
  tape('multiple bytes from multiple buffers', function (t) {
75
76
  var bl = new BufferList()
76
77
 
77
- bl.append(new Buffer('abcd'))
78
- bl.append(new Buffer('efg'))
79
- bl.append(new Buffer('hi'))
80
- 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'))
81
82
 
82
83
  t.equal(bl.length, 10)
83
84
 
@@ -94,8 +95,8 @@ tape('multiple bytes from multiple buffers', function (t) {
94
95
  tape('multiple bytes from multiple buffer lists', function (t) {
95
96
  var bl = new BufferList()
96
97
 
97
- bl.append(new BufferList([ new Buffer('abcd'), new Buffer('efg') ]))
98
- 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') ]))
99
100
 
100
101
  t.equal(bl.length, 10)
101
102
 
@@ -115,12 +116,12 @@ tape('multiple bytes from crazy nested buffer lists', function (t) {
115
116
 
116
117
  bl.append(new BufferList([
117
118
  new BufferList([
118
- new BufferList(new Buffer('abc'))
119
- , new Buffer('d')
120
- , new BufferList(new Buffer('efg'))
119
+ new BufferList(Buffer.from('abc'))
120
+ , Buffer.from('d')
121
+ , new BufferList(Buffer.from('efg'))
121
122
  ])
122
- , new BufferList([ new Buffer('hi') ])
123
- , new BufferList(new Buffer('j'))
123
+ , new BufferList([ Buffer.from('hi') ])
124
+ , new BufferList(Buffer.from('j'))
124
125
  ]))
125
126
 
126
127
  t.equal(bl.length, 10)
@@ -137,10 +138,10 @@ tape('multiple bytes from crazy nested buffer lists', function (t) {
137
138
 
138
139
  tape('append accepts arrays of Buffers', function (t) {
139
140
  var bl = new BufferList()
140
- bl.append(new Buffer('abc'))
141
- bl.append([ new Buffer('def') ])
142
- bl.append([ new Buffer('ghi'), new Buffer('jkl') ])
143
- 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') ])
144
145
  t.equal(bl.length, 26)
145
146
  t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
146
147
  t.end()
@@ -148,10 +149,10 @@ tape('append accepts arrays of Buffers', function (t) {
148
149
 
149
150
  tape('append accepts arrays of BufferLists', function (t) {
150
151
  var bl = new BufferList()
151
- bl.append(new Buffer('abc'))
152
+ bl.append(Buffer.from('abc'))
152
153
  bl.append([ new BufferList('def') ])
153
- bl.append(new BufferList([ new Buffer('ghi'), new BufferList('jkl') ]))
154
- 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') ]) ])
155
156
  t.equal(bl.length, 26)
156
157
  t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
157
158
  t.end()
@@ -159,18 +160,18 @@ tape('append accepts arrays of BufferLists', function (t) {
159
160
 
160
161
  tape('append chainable', function (t) {
161
162
  var bl = new BufferList()
162
- t.ok(bl.append(new Buffer('abcd')) === bl)
163
- t.ok(bl.append([ new Buffer('abcd') ]) === bl)
164
- t.ok(bl.append(new BufferList(new Buffer('abcd'))) === bl)
165
- 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)
166
167
  t.end()
167
168
  })
168
169
 
169
170
  tape('append chainable (test results)', function (t) {
170
171
  var bl = new BufferList('abc')
171
172
  .append([ new BufferList('def') ])
172
- .append(new BufferList([ new Buffer('ghi'), new BufferList('jkl') ]))
173
- .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') ]) ])
174
175
 
175
176
  t.equal(bl.length, 26)
176
177
  t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
@@ -180,10 +181,10 @@ tape('append chainable (test results)', function (t) {
180
181
  tape('consuming from multiple buffers', function (t) {
181
182
  var bl = new BufferList()
182
183
 
183
- bl.append(new Buffer('abcd'))
184
- bl.append(new Buffer('efg'))
185
- bl.append(new Buffer('hi'))
186
- 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'))
187
188
 
188
189
  t.equal(bl.length, 10)
189
190
 
@@ -215,8 +216,8 @@ tape('consuming from multiple buffers', function (t) {
215
216
  tape('complete consumption', function (t) {
216
217
  var bl = new BufferList()
217
218
 
218
- bl.append(new Buffer('a'))
219
- bl.append(new Buffer('b'))
219
+ bl.append(Buffer.from('a'))
220
+ bl.append(Buffer.from('b'))
220
221
 
221
222
  bl.consume(2)
222
223
 
@@ -227,9 +228,9 @@ tape('complete consumption', function (t) {
227
228
  })
228
229
 
229
230
  tape('test readUInt8 / readInt8', function (t) {
230
- var buf1 = new Buffer(1)
231
- , buf2 = new Buffer(3)
232
- , buf3 = new Buffer(3)
231
+ var buf1 = Buffer.alloc(1)
232
+ , buf2 = Buffer.alloc(3)
233
+ , buf3 = Buffer.alloc(3)
233
234
  , bl = new BufferList()
234
235
 
235
236
  buf2[1] = 0x3
@@ -253,9 +254,9 @@ tape('test readUInt8 / readInt8', function (t) {
253
254
  })
254
255
 
255
256
  tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t) {
256
- var buf1 = new Buffer(1)
257
- , buf2 = new Buffer(3)
258
- , buf3 = new Buffer(3)
257
+ var buf1 = Buffer.alloc(1)
258
+ , buf2 = Buffer.alloc(3)
259
+ , buf3 = Buffer.alloc(3)
259
260
  , bl = new BufferList()
260
261
 
261
262
  buf2[1] = 0x3
@@ -283,9 +284,9 @@ tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t
283
284
  })
284
285
 
285
286
  tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t) {
286
- var buf1 = new Buffer(1)
287
- , buf2 = new Buffer(3)
288
- , buf3 = new Buffer(3)
287
+ var buf1 = Buffer.alloc(1)
288
+ , buf2 = Buffer.alloc(3)
289
+ , buf3 = Buffer.alloc(3)
289
290
  , bl = new BufferList()
290
291
 
291
292
  buf2[1] = 0x3
@@ -305,9 +306,9 @@ tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t
305
306
  })
306
307
 
307
308
  tape('test readFloatLE / readFloatBE', function (t) {
308
- var buf1 = new Buffer(1)
309
- , buf2 = new Buffer(3)
310
- , buf3 = new Buffer(3)
309
+ var buf1 = Buffer.alloc(1)
310
+ , buf2 = Buffer.alloc(3)
311
+ , buf3 = Buffer.alloc(3)
311
312
  , bl = new BufferList()
312
313
 
313
314
  buf2[1] = 0x00
@@ -324,9 +325,9 @@ tape('test readFloatLE / readFloatBE', function (t) {
324
325
  })
325
326
 
326
327
  tape('test readDoubleLE / readDoubleBE', function (t) {
327
- var buf1 = new Buffer(1)
328
- , buf2 = new Buffer(3)
329
- , buf3 = new Buffer(10)
328
+ var buf1 = Buffer.alloc(1)
329
+ , buf2 = Buffer.alloc(3)
330
+ , buf3 = Buffer.alloc(10)
330
331
  , bl = new BufferList()
331
332
 
332
333
  buf2[1] = 0x55
@@ -349,10 +350,10 @@ tape('test readDoubleLE / readDoubleBE', function (t) {
349
350
  tape('test toString', function (t) {
350
351
  var bl = new BufferList()
351
352
 
352
- bl.append(new Buffer('abcd'))
353
- bl.append(new Buffer('efg'))
354
- bl.append(new Buffer('hi'))
355
- 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'))
356
357
 
357
358
  t.equal(bl.toString('ascii', 0, 10), 'abcdefghij')
358
359
  t.equal(bl.toString('ascii', 3, 10), 'defghij')
@@ -365,13 +366,13 @@ tape('test toString', function (t) {
365
366
 
366
367
  tape('test toString encoding', function (t) {
367
368
  var bl = new BufferList()
368
- , b = new Buffer('abcdefghij\xff\x00')
369
+ , b = Buffer.from('abcdefghij\xff\x00')
369
370
 
370
- bl.append(new Buffer('abcd'))
371
- bl.append(new Buffer('efg'))
372
- bl.append(new Buffer('hi'))
373
- bl.append(new Buffer('j'))
374
- 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'))
375
376
 
376
377
  encodings.forEach(function (enc) {
377
378
  t.equal(bl.toString(enc), b.toString(enc), enc)
@@ -419,7 +420,7 @@ tape('instantiation with Buffer', function (t) {
419
420
 
420
421
  tape('test String appendage', function (t) {
421
422
  var bl = new BufferList()
422
- , b = new Buffer('abcdefghij\xff\x00')
423
+ , b = Buffer.from('abcdefghij\xff\x00')
423
424
 
424
425
  bl.append('abcd')
425
426
  bl.append('efg')
@@ -436,7 +437,7 @@ tape('test String appendage', function (t) {
436
437
 
437
438
  tape('test Number appendage', function (t) {
438
439
  var bl = new BufferList()
439
- , b = new Buffer('1234567890')
440
+ , b = Buffer.from('1234567890')
440
441
 
441
442
  bl.append(1234)
442
443
  bl.append(567)
@@ -470,7 +471,7 @@ tape('unicode string', function (t) {
470
471
  bl.write(' and ')
471
472
  bl.write(inp2)
472
473
  t.equal(exp, bl.toString())
473
- t.equal(new Buffer(exp).toString('hex'), bl.toString('hex'))
474
+ t.equal(Buffer.from(exp).toString('hex'), bl.toString('hex'))
474
475
  })
475
476
 
476
477
  tape('should emit finish', function (t) {
@@ -488,7 +489,7 @@ tape('should emit finish', function (t) {
488
489
 
489
490
  tape('basic copy', function (t) {
490
491
  var buf = crypto.randomBytes(1024)
491
- , buf2 = new Buffer(1024)
492
+ , buf2 = Buffer.alloc(1024)
492
493
  , b = BufferList(buf)
493
494
 
494
495
  b.copy(buf2)
@@ -498,7 +499,7 @@ tape('basic copy', function (t) {
498
499
 
499
500
  tape('copy after many appends', function (t) {
500
501
  var buf = crypto.randomBytes(512)
501
- , buf2 = new Buffer(1024)
502
+ , buf2 = Buffer.alloc(1024)
502
503
  , b = BufferList(buf)
503
504
 
504
505
  b.append(buf)
@@ -509,7 +510,7 @@ tape('copy after many appends', function (t) {
509
510
 
510
511
  tape('copy at a precise position', function (t) {
511
512
  var buf = crypto.randomBytes(1004)
512
- , buf2 = new Buffer(1024)
513
+ , buf2 = Buffer.alloc(1024)
513
514
  , b = BufferList(buf)
514
515
 
515
516
  b.copy(buf2, 20)
@@ -519,7 +520,7 @@ tape('copy at a precise position', function (t) {
519
520
 
520
521
  tape('copy starting from a precise location', function (t) {
521
522
  var buf = crypto.randomBytes(10)
522
- , buf2 = new Buffer(5)
523
+ , buf2 = Buffer.alloc(5)
523
524
  , b = BufferList(buf)
524
525
 
525
526
  b.copy(buf2, 0, 5)
@@ -530,8 +531,8 @@ tape('copy starting from a precise location', function (t) {
530
531
  tape('copy in an interval', function (t) {
531
532
  var rnd = crypto.randomBytes(10)
532
533
  , b = BufferList(rnd) // put the random bytes there
533
- , actual = new Buffer(3)
534
- , expected = new Buffer(3)
534
+ , actual = Buffer.alloc(3)
535
+ , expected = Buffer.alloc(3)
535
536
 
536
537
  rnd.copy(expected, 0, 5, 8)
537
538
  b.copy(actual, 0, 5, 8)
@@ -542,7 +543,7 @@ tape('copy in an interval', function (t) {
542
543
 
543
544
  tape('copy an interval between two buffers', function (t) {
544
545
  var buf = crypto.randomBytes(10)
545
- , buf2 = new Buffer(10)
546
+ , buf2 = Buffer.alloc(10)
546
547
  , b = BufferList(buf)
547
548
 
548
549
  b.append(buf)
@@ -589,7 +590,7 @@ tape('shallow slice with negative or omitted indices', function (t) {
589
590
 
590
591
  tape('shallow slice does not make a copy', function (t) {
591
592
  t.plan(1)
592
- var buffers = [new Buffer('First'), new Buffer('Second'), new Buffer('Third')]
593
+ var buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
593
594
  var bl = (new BufferList(buffers)).shallowSlice(5, -3)
594
595
 
595
596
  buffers[1].fill('h')
package/.npmignore DELETED
@@ -1 +0,0 @@
1
- node_modules/