Skip to content

Commit

Permalink
feat!: added bigint (Int64) support
Browse files Browse the repository at this point in the history
Breaking because this drops support for Node.js <= 12
  • Loading branch information
yuyaryshev authored and rvagg committed Oct 19, 2022
1 parent 3af8c54 commit 131ad32
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions BufferList.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ BufferList.prototype._match = function (offset, search) {
readDoubleLE: 8,
readFloatBE: 4,
readFloatLE: 4,
readBigInt64BE: 8,
readBigInt64LE: 8,
readBigUInt64BE: 8,
readBigUInt64LE: 8,
readInt32BE: 4,
readInt32LE: 4,
readUInt32BE: 4,
Expand Down
34 changes: 34 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,40 @@ tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t
t.end()
})

tape('test readBigUInt64LE / readBigUInt64BE / readBigInt64LE / readBigInt64BE', function (t) {
const buf1 = Buffer.alloc(1)
const buf2 = Buffer.alloc(3)
const buf3 = Buffer.alloc(2)
const buf4 = Buffer.alloc(5)
const bl = new BufferListStream()

buf1[0] = 0x05
buf2[0] = 0x07

buf2[1] = 0x03
buf2[2] = 0x04
buf3[0] = 0x23
buf3[1] = 0x42
buf4[0] = 0x00
buf4[1] = 0x01
buf4[2] = 0x02
buf4[3] = 0x03

buf4[4] = 0x04

bl.append(buf1)
bl.append(buf2)
bl.append(buf3)
bl.append(buf4)

t.equal(bl.readBigUInt64BE(2), 0x0304234200010203n)
t.equal(bl.readBigUInt64LE(2), 0x0302010042230403n)
t.equal(bl.readBigInt64BE(2), 0x0304234200010203n)
t.equal(bl.readBigInt64LE(2), 0x0302010042230403n)

t.end()
})

tape('test readUIntLE / readUIntBE / readIntLE / readIntBE', function (t) {
const buf1 = Buffer.alloc(1)
const buf2 = Buffer.alloc(3)
Expand Down

0 comments on commit 131ad32

Please sign in to comment.