@chickenjdk/byteutils
    Preparing search index...

    Class chunkingWritableStream

    Hierarchy (View Summary)

    Index

    Constructors

    • Write to the stream in predictable sized chunks. This is useful for high speed/bandwidth writes to a stream, as it prevents memory issues with large writes and spamming the stream. It accomplishes this by writing data with predictably sized chunks, regardless of how small or large the writes are. If you need the data written immediately, you can use the flush method to write the current buffer to the stream. If you need each write to be written immediately, use writableStream instead.

      Parameters

      • stream: Writable

        The stream to write to.

      • chunkSize: number = 2000

        The size of the chunks to write to the stream.

      Returns chunkingWritableStream

    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 chunkSize(): number

      The size of the chunks to write to the stream. If you need to change it, please use the setChunkSize method.

      Returns number

      The size of the chunks to write to the stream.

      2000
      
    • 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

    • get stream(): Writable

      The stream we are writing to.

      Returns Writable

      TThe stream we are writing to.

    Methods

    • Flush the buffer to the stream. If the buffer is empty, it resolves immediately. If the buffer is not empty, it writes the used section of the buffer to the stream and resets the buffer. This is useful for ensuring that all data is sent to the stream before closing it or performing other operations.

      Returns Promise<void>

      A promise that resolves when the buffer is flushed.

    • 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.

    • Change the chunk size of the stream. This is async because it may need to flush the current buffer if the new chunk size is smaller than the current used size.

      Parameters

      • value: number

        The new chunk size to set.

      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)