👓💯 Read Unsigned/Signed Big/Little-Endian BigInt from Buffer
npm install read-bigint
- Supported Node versions aim to be Latest current and LTS as well as trying to keep up to date with the latest supported node in Google cloud functions.
import {
readBigInt64BE,
readBigInt64LE,
readBigUInt64BE,
readBigUInt64LE,
} from "read-bigint";
const buffer = Buffer.from([
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
]);
readBigInt64BE(buffer, /* offset */ 1); // => 1234605616436508552n
readBigInt64LE(buffer, /* offset */ 1); // => -8613303245920329199n
readBigUInt64BE(buffer, /* offset */ 1); // => 1234605616436508552n
readBigUInt64LE(buffer, /* offset */ 1); // => 9833440827789222417n
The purpose of this package is to be able to read native BigInt from native Buffer. This is mostly useful when targeting Node 10 (LTS Dubnium), which supports BigInt, but does not have native methods for reading BigInt from Buffer. On Node 12 or any later version of Node, you should use the native Buffer methods instead.
Each of the exported methods is a direct copy of the Native Buffer.readBigInt() methods.
-
readBigInt64BE(buffer, offset)
Copy of native
buffer.readBigInt64BE(offset)
-
readBigInt64LE(buffer, offset)
Copy of native
buffer.readBigInt64LE(offset)
-
readBigUInt64BE(buffer, offset)
Copy of native
buffer.readBigUInt64LE(offset)
-
readBigUInt64BE(buffer, offset)
Copy of native
buffer.readBigUInt64LE(offset)
MIT