Open In App

Node.js Buffer.readBigInt64LE() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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

Syntax: 

buffer.readBigInt64LE( offset )

Parameters: This method accepts a single parameter offset that 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 a signed 64-bit Big integer at the specified offset in Little endian.
 

Example 1: 

Filename: index.js 

javascript




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


Run index.js file using the following command: 
 

node index.js

Output: 
 

Big Integer :- -4294967296

Example 2: 
 

Filename: index.js 

javascript




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


Run 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.readBigInt64LE (internal/buffer.js:128: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_readbigint64le_offset
 



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