Open In App

Node.js Buffer.readBigUInt64LE() Method

Improve
Improve
Like Article
Like
Save
Share
Report

The Buffer.readBigUInt64LE() method is used to read unsigned 64 bit integer from a buffer object at a given offset and returns the result in Little endian.
Syntax: 

buffer.readBigUInt64LE( offset )

Parameters: This method accepts a single parameter offset which specifies the position of buffer object. It represents the number of bytes to skip before starting to read. The value of offset lies within the range 0 to buffer.length – 8. The default value is 0.

Return value: This method reads an unsigned 64-bit integer at the specified offset in Little endian.

Example 1: 
Filename: index.js 

javascript




// Node.js program to demonstrate the
// buffer.readBigUInt64LE() method
const buff = Buffer.from([0x00, 0x00,
    0x0e, 0x00, 0xff, 0xff, 0xff, 0xff]);
 
// Getting big integer value by
// using readBigUInt64LE method
const value = buff.readBigUInt64LE(0);
 
// Display the result
console.log("Big Integer :- " + value);


Run the index.js file using the following command: 

node index.js

Output: 

Big Integer :- 18446744069415501824

Example 2: 
Filename: index.js 

javascript




// Node.js program to demonstrate the
// buffer.readBigUInt64LE() method
const buff = Buffer.from([0x00, 0x00,
    0x0e, 0x00, 0xff, 0xff, 0xff, 0xff]);
 
// Getting big integer value by
// using readBigUInt64LE method
const value = buff.readBigUInt64LE(1);
 
// Display the result
console.log("Big Integer :- " + value);


Run the index.js file using the following command: 

node index.js

Output:  

internal/buffer.js:77
  throw new ERR_OUT_OF_RANGE(type || 'offset',
  ^

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and
 <= 0. Received 1
    at boundsError (internal/buffer.js:77:9)
    at Buffer.readBigUInt64LE (internal/buffer.js:88:5)
    at Object. (F:\java\GFG.js:7:20)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'ERR_OUT_OF_RANGE'
}

The above example shows the error because its parameters are not in the valid range.

Reference: https://nodejs.org/dist/latest-v12.x/docs/api/buffer.html#buffer_buf_readbiguint64le_offset
 



Last Updated : 27 Jan, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads