Buffer.writeBigUInt64LE()
methodThe Buffer.writeBigUInt64LE()
method in Node.js is used to write 64-bits from a specified offset to a buffer in
The Buffer.writeBigUInt64LE()
method can be declared as shown in the code snippet below:
Buffer.writeBigUInt64LE(value, offset)
value
: A 64-bit unsigned integer to be written in the buffer.
offset
: The offset determines the number of bytes to skip before writing to the buffer.
In other words, it is the index of the buffer.
- The
offset
value should be greater than -1 and less than (bufferLength - 7).- The default value of
offset
is 0.
The Buffer.writeBigUInt64LE()
method returns an integer whose value is offset
+ the number of bytes written to the buffer.
Consider the code snippet below, it demonstrates how to use the Buffer.writeBigUInt64LE()
method:
const buff = Buffer.allocUnsafe(8);buff.writeBigUInt64LE(0xabcdef1234567890n, 0);console.log(buff);
<Buffer 90 78 56 34 12 ef cd ab>
In line 1, we declare a buffer, buff
.
The writeBigUInt64LE()
method is used in line 3 to write 64-bits from index 0 in the little-endian format.
Since one index of the buffer is 8-bits, we need to write at 8 indices of buff
.
The writeBigUInt64LE()
method writes at 8 indices of buff
starting from index 0
, i.e., index = 0
- index + 8 - 1 = 7
.
Since the code is in the little Endian format, index 7 is written before index 6, index 6 is written before index 5, and so on.