@chickenjdk/byteutils
    Preparing search index...

    Class writableStream

    Hierarchy (View Summary)

    Index

    Constructors

    • Write binary encoded data to a stream. Writes each write to the stream immeditly, no matter the size of the data. For this reason, for high speed/bandwidth, it is recommended to use chunkingWritableStream to prevent memory issues with large writes and spamming the stream. This is accomplished by writing data with predictably sized chunks, regardless of how small or large the writes are.

      Parameters

      • stream: Writable

        The stream to write to.

      Returns writableStream

    Properties

    writeArrayBackwardsEndian:
        | ((...args: [value: number[]]) => Promise)
        | ((...args: [value: number[]]) => Promise) = ...

    Write data to the buffer backwards (writes data that was origionaly in LE format to the endianness of the buffer, I know that "backwards" is a little opinionated but the class was origionaly BE-only and I did not want to change too mutch)

    The data to write

    writeArrayEndian:
        | ((...args: [value: number[]]) => Promise)
        | ((...args: [value: number[]]) => Promise) = ...

    Write data to the buffer (writes data that was origionaly in BE format to the endianness of the buffer)

    The data to write

    writeUint8ArrayBackwardsEndian:
        | ((...args: [value: Uint8Array<ArrayBufferLike>]) => Promise)
        | ((...args: [value: Uint8Array<ArrayBufferLike>]) => Promise) = ...

    Write a Uint8Array to the buffer backwars (for the endian) Alias for .write because .write can handle Uint8Arrays. This exsists to have the similar naming of methods as readableBuffer's methods

    writeUint8ArrayEndian:
        | ((...args: [value: Uint8Array<ArrayBufferLike>]) => Promise)
        | ((...args: [value: Uint8Array<ArrayBufferLike>]) => Promise) = ...

    Write a Uint8Array to the buffer (for the endian) Alias for .write because .write can handle Uint8Arrays. This exsists to have the similar naming of methods as readableBuffer's methods

    Accessors

    • get isLe(): boolean

      If the buffer is little endian

      Returns boolean

    • set isLe(isLe: boolean): void

      If the buffer is little endian

      Parameters

      • isLe: boolean

      Returns void

    Methods

    • Calculate the minimum length of a signed integer in bytes. WARNING: No signed integers above 4278190079 or below -4278190079 (2^31 - 1) are supported, so this will not work for those. This is due to the limitations of bitwise operators. You can write numbers higher than that via writeSignedIntegerBigint, but this function will not work for them.

      Parameters

      • value: number

        The value to check

      Returns number

      The calculated minimum length in bytes

      This function calculates the minimum number of bytes needed to represent a signed integer in binary format. It uses the Math.clz32 function to count the number of leading zeros in the binary representation of the value. It subtracts this from 33 (equivilent to the number of bits in the signed integer +1 to account for the sign) to get the number of bits needed. The result is rounded up to the nearest byte.

    • Calculate the minimum length of a signed ones's complement in bytes. WARNING: No signed two's complements above 4278190079 or below -4278190079 (2^31 - 1) are supported, so this will not work for those. This is due to the limitations of bitwise operators. You can write numbers higher than that via writeSignedOnesComplementBigint, but this function will not work for them.

      Parameters

      • value: number

        The value to check

      Returns number

      The calculated minimum length in bytes

      This function calculates the minimum number of bytes needed to represent an signed one's in binary format. It uses the Math.clz32 function to count the number of leading zeros in the binary representation of the value. It subtracts this from 33 (equivilent to the number of bits in the signed one's complement +1 to account for the sign) to get the number of bits needed. The result is rounded up to the nearest byte.

    • Calculate the minimum length of a two's complement in bytes. WARNING: No two's complements above 4278190079 or below -4278190079 (2^31 - 1) are supported, so this will not work for those. This is due to the limitations of bitwise operators. You can write numbers higher than that via writeTwosComplementBigint, but this function will not work for them.

      Parameters

      • value: number

        The value to check

      Returns number

      The calculated minimum length in bytes

      This function calculates the minimum number of bytes needed to represent an two's complement in binary format. It uses the Math.clz32 function to count the number of leading zeros in the binary representation of the value. It subtracts this from 33 (equivilent to the number of bits in the two's complement +1 to account for the sign) to get the number of bits needed. The result is rounded up to the nearest byte.

    • Calculate the minimum length of an unsigned integer in bytes. WARNING: No unssigned ints above 4294967295 (2^32 - 1) are supported, so this will not work for those. This is due to the limitations of bitwise operators. You can write numbers higher than that via writeUnsignedIntBigint, but this function will not work for them.

      Parameters

      • value: number

        The value to check

      Returns number

      The calculated minimum length in bytes

      This function calculates the minimum number of bytes needed to represent an unsigned integer in binary format. It uses the Math.clz32 function to count the number of leading zeros in the binary representation of the value. The result is rounded up to the nearest byte.

    • Write a array of bytes (numbers 0-255) to the buffer (first byte first written to the end[BE])

      Parameters

      • value: number[]

        The data to write

      Returns Promise<void>

    • Encode and write a signed integer

      Parameters

      • value: number

        The number to encode

      • bytes: number

        How many bytes to make the encoded value

      Returns Promise<number>

      How many bytes were written (Same as bytes parameter if provided)

    • Encode and write a signed integer (from a bigint)

      Parameters

      • value: bigint

        The number to encode

      • bytes: number

        How many bytes to make the encoded value

      Returns Promise<number>

      How many bytes were written (Same as bytes parameter)

    • Encode and write a signed one's complement

      Parameters

      • value: number

        The number to encode

      • bytes: number

        How many bytes to make the encoded value

      Returns Promise<number>

      How many bytes were written (Same as bytes parameter if provided)

    • Encode and write a signed ones complement (from a bigint)

      Parameters

      • value: bigint

        The number to encode

      • bytes: number

        How many bytes to make the encoded value

      Returns Promise<number>

      How many bytes were written (Same as bytes parameter)

    • Write a utf8 string to the buffer

      Parameters

      • value: string
      • mutf8: boolean = false

        If true, write in java's mutf8 format instead. This was build for parsing java's .class files, so no complaining about it being a java-specific format.

      Returns Promise<number>

      How many bytes were written

    • Write a twos complement to the buffer

      Parameters

      • value: number

        The number to encode

      • bytes: number

        How long the twos complement to be written is in bytes

      Returns Promise<number>

      How many bytes were written (Same as bytes parameter if provided)

    • Write a twos complement to the buffer (From a bigint)

      Parameters

      • value: bigint

        The number to encode

      • bytes: number

        How long the twos complement to be written is in bytes

      Returns Promise<number>

      How many bytes were written (Same as bytes parameter)

    • Write an unsigned integer to the buffer

      Parameters

      • value: number

        The unsigned int to write

      • bytes: number

        How many bytes the unsined int is (If not provided, it will write the minimum length)

      Returns Promise<number>

      How many bytes were written (Same as bytes parameter if provided)

    • Write an unsigned integer to the buffer

      Parameters

      • value: bigint

        The unsigned int to write (a bigint)

      • bytes: number

        How many bytes the unsined int is (If not provided, it will write the minimum length)

      Returns Promise<number>

      How many bytes were written (Same as bytes parameter)