Skip to content

Commit 131ad32

Browse files
yuyaryshevrvagg
authored andcommitted
feat!: added bigint (Int64) support
Breaking because this drops support for Node.js <= 12
1 parent 3af8c54 commit 131ad32

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

BufferList.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ BufferList.prototype._match = function (offset, search) {
350350
readDoubleLE: 8,
351351
readFloatBE: 4,
352352
readFloatLE: 4,
353+
readBigInt64BE: 8,
354+
readBigInt64LE: 8,
355+
readBigUInt64BE: 8,
356+
readBigUInt64LE: 8,
353357
readInt32BE: 4,
354358
readInt32LE: 4,
355359
readUInt32BE: 4,

test/test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,40 @@ tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t
388388
t.end()
389389
})
390390

391+
tape('test readBigUInt64LE / readBigUInt64BE / readBigInt64LE / readBigInt64BE', function (t) {
392+
const buf1 = Buffer.alloc(1)
393+
const buf2 = Buffer.alloc(3)
394+
const buf3 = Buffer.alloc(2)
395+
const buf4 = Buffer.alloc(5)
396+
const bl = new BufferListStream()
397+
398+
buf1[0] = 0x05
399+
buf2[0] = 0x07
400+
401+
buf2[1] = 0x03
402+
buf2[2] = 0x04
403+
buf3[0] = 0x23
404+
buf3[1] = 0x42
405+
buf4[0] = 0x00
406+
buf4[1] = 0x01
407+
buf4[2] = 0x02
408+
buf4[3] = 0x03
409+
410+
buf4[4] = 0x04
411+
412+
bl.append(buf1)
413+
bl.append(buf2)
414+
bl.append(buf3)
415+
bl.append(buf4)
416+
417+
t.equal(bl.readBigUInt64BE(2), 0x0304234200010203n)
418+
t.equal(bl.readBigUInt64LE(2), 0x0302010042230403n)
419+
t.equal(bl.readBigInt64BE(2), 0x0304234200010203n)
420+
t.equal(bl.readBigInt64LE(2), 0x0302010042230403n)
421+
422+
t.end()
423+
})
424+
391425
tape('test readUIntLE / readUIntBE / readIntLE / readIntBE', function (t) {
392426
const buf1 = Buffer.alloc(1)
393427
const buf2 = Buffer.alloc(3)

0 commit comments

Comments
 (0)