Polyfill for BigInt support in Buffer

Example

import '@vekexasia/bigint-buffer-polyfill';

const buf = Buffer.alloc(16);
buf.writeBigIntBE(-42n, 8);
buf.writeBigUIntLE(69n, 8, 8);

console.log(buf.readBigIntBE(8)); // -42n
console.log(buf.readBigUIntLE(8, 8)); // 69n
interface Buffer {
    readBigIntBE(width, offset?): bigint;
    readBigIntLE(width, offset?): bigint;
    readBigUIntBE(width, offset?): bigint;
    readBigUIntLE(width, offset?): bigint;
    writeBigIntBE(value, width, offset?): number;
    writeBigIntLE(value, width, offset?): number;
    writeBigUIntBE(value, width, offset?): number;
    writeBigUIntLE(value, width, offset?): number;
}

Methods

  • Read a signed BigInt from a buffer in Big Endian format

    Parameters

    • width: number

      the number of bytes to read

    • Optional offset: number

      the offset to read from

    Returns bigint

    the value read

  • Read a signed BigInt from a buffer in Little Endian format

    Parameters

    • width: number

      the number of bytes to read

    • Optional offset: number

      the offset to read from

    Returns bigint

    the value read

  • Read an unsigned BigInt from a buffer in Big Endian format

    Parameters

    • width: number

      the number of bytes to read

    • Optional offset: number

      the offset to read from

    Returns bigint

    the value read

  • Read an unsigned BigInt from a buffer in Little Endian format

    Parameters

    • width: number

      the number of bytes to read

    • Optional offset: number

      the offset to read from

    Returns bigint

    the value read

  • Write a signed BigInt to a buffer in Big Endian format

    Parameters

    • value: bigint

      the value to write

    • width: number

      the number of bytes to write

    • Optional offset: number

      the offset to write at

    Returns number

    the number of bytes written

  • Write a signed BigInt to a buffer in Little Endian format

    Parameters

    • value: bigint

      the value to write

    • width: number

      the number of bytes to write

    • Optional offset: number

      the offset to write at

    Returns number

    the number of bytes written

  • Write an unsigned BigInt to a buffer in Big Endian format

    Parameters

    • value: bigint

      the value to write

    • width: number

      the number of bytes to write

    • Optional offset: number

      the offset to write at

    Returns number

    the number of bytes written

  • Write an unsigned BigInt to a buffer in Little Endian format

    Parameters

    • value: bigint

      the value to write

    • width: number

      the number of bytes to write

    • Optional offset: number

      the offset to write at

    Returns number

    the number of bytes written

Generated using TypeDoc