bl 4.0.4 → 4.1.0

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/BufferList.js CHANGED
@@ -373,7 +373,7 @@ BufferList.prototype._match = function (offset, search) {
373
373
  return this.slice(offset, offset + byteLength)[m](0, byteLength)
374
374
  }
375
375
  } else {
376
- BufferList.prototype[m] = function (offset) {
376
+ BufferList.prototype[m] = function (offset = 0) {
377
377
  return this.slice(offset, offset + methods[m])[m](0)
378
378
  }
379
379
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bl",
3
- "version": "4.0.4",
3
+ "version": "4.1.0",
4
4
  "description": "Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too!",
5
5
  "license": "MIT",
6
6
  "main": "bl.js",
package/test/test.js CHANGED
@@ -265,6 +265,7 @@ tape('test readUInt8 / readInt8', function (t) {
265
265
  const buf3 = Buffer.alloc(3)
266
266
  const bl = new BufferList()
267
267
 
268
+ buf1[0] = 0x1
268
269
  buf2[1] = 0x3
269
270
  buf2[2] = 0x4
270
271
  buf3[0] = 0x23
@@ -274,6 +275,7 @@ tape('test readUInt8 / readInt8', function (t) {
274
275
  bl.append(buf2)
275
276
  bl.append(buf3)
276
277
 
278
+ t.equal(bl.readUInt8(), 0x1)
277
279
  t.equal(bl.readUInt8(2), 0x3)
278
280
  t.equal(bl.readInt8(2), 0x3)
279
281
  t.equal(bl.readUInt8(3), 0x4)
@@ -292,6 +294,7 @@ tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t
292
294
  const buf3 = Buffer.alloc(3)
293
295
  const bl = new BufferList()
294
296
 
297
+ buf1[0] = 0x1
295
298
  buf2[1] = 0x3
296
299
  buf2[2] = 0x4
297
300
  buf3[0] = 0x23
@@ -301,6 +304,8 @@ tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t
301
304
  bl.append(buf2)
302
305
  bl.append(buf3)
303
306
 
307
+ t.equal(bl.readUInt16BE(), 0x0100)
308
+ t.equal(bl.readUInt16LE(), 0x0001)
304
309
  t.equal(bl.readUInt16BE(2), 0x0304)
305
310
  t.equal(bl.readUInt16LE(2), 0x0403)
306
311
  t.equal(bl.readInt16BE(2), 0x0304)
@@ -323,6 +328,7 @@ tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t
323
328
  const buf3 = Buffer.alloc(3)
324
329
  const bl = new BufferList()
325
330
 
331
+ buf1[0] = 0x1
326
332
  buf2[1] = 0x3
327
333
  buf2[2] = 0x4
328
334
  buf3[0] = 0x23
@@ -332,6 +338,8 @@ tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t
332
338
  bl.append(buf2)
333
339
  bl.append(buf3)
334
340
 
341
+ t.equal(bl.readUInt32BE(), 0x01000304)
342
+ t.equal(bl.readUInt32LE(), 0x04030001)
335
343
  t.equal(bl.readUInt32BE(2), 0x03042342)
336
344
  t.equal(bl.readUInt32LE(2), 0x42230403)
337
345
  t.equal(bl.readInt32BE(2), 0x03042342)
@@ -391,6 +399,7 @@ tape('test readFloatLE / readFloatBE', function (t) {
391
399
  const buf3 = Buffer.alloc(3)
392
400
  const bl = new BufferList()
393
401
 
402
+ buf1[0] = 0x01
394
403
  buf2[1] = 0x00
395
404
  buf2[2] = 0x00
396
405
  buf3[0] = 0x80
@@ -400,7 +409,11 @@ tape('test readFloatLE / readFloatBE', function (t) {
400
409
  bl.append(buf2)
401
410
  bl.append(buf3)
402
411
 
403
- t.equal(bl.readFloatLE(2), 0x01)
412
+ const canonical = Buffer.concat([buf1, buf2, buf3])
413
+ t.equal(bl.readFloatLE(), canonical.readFloatLE())
414
+ t.equal(bl.readFloatBE(), canonical.readFloatBE())
415
+ t.equal(bl.readFloatLE(2), canonical.readFloatLE(2))
416
+ t.equal(bl.readFloatBE(2), canonical.readFloatBE(2))
404
417
 
405
418
  t.end()
406
419
  })
@@ -411,6 +424,7 @@ tape('test readDoubleLE / readDoubleBE', function (t) {
411
424
  const buf3 = Buffer.alloc(10)
412
425
  const bl = new BufferList()
413
426
 
427
+ buf1[0] = 0x01
414
428
  buf2[1] = 0x55
415
429
  buf2[2] = 0x55
416
430
  buf3[0] = 0x55
@@ -424,7 +438,11 @@ tape('test readDoubleLE / readDoubleBE', function (t) {
424
438
  bl.append(buf2)
425
439
  bl.append(buf3)
426
440
 
427
- t.equal(bl.readDoubleLE(2), 0.3333333333333333)
441
+ const canonical = Buffer.concat([buf1, buf2, buf3])
442
+ t.equal(bl.readDoubleBE(), canonical.readDoubleBE())
443
+ t.equal(bl.readDoubleLE(), canonical.readDoubleLE())
444
+ t.equal(bl.readDoubleBE(2), canonical.readDoubleBE(2))
445
+ t.equal(bl.readDoubleLE(2), canonical.readDoubleLE(2))
428
446
 
429
447
  t.end()
430
448
  })