The stream to write to.
The size of the chunks to write to the stream.
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)
Write data to the buffer (writes data that was origionaly in BE format to the endianness of the buffer)
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
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
If the buffer is little endian
If the buffer is little endian
The stream we are writing to.
TThe stream we are writing to.
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.
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.
The value to check
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.
The value to check
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.
The value to check
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.
The value to check
The calculated minimum length in bytes
Push a byte (numbers 0-255) to the buffer's end
the byte to push
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.
The new chunk size to set.
Write a array of bytes (numbers 0-255) to the buffer (first byte first written to the end[BE])
The data to write
Write a array of bytes (numbers 0-255) to the buffer backwards (last byte first written to the end[LE])
Write a double float to the buffer
The double float to write
How many bytes were written (8)
Write a float to the buffer
The float to write
How many bytes were written (4)
Encode and write a signed integer
The number to encode
How many bytes to make the encoded value
How many bytes were written (Same as bytes parameter if provided)
Encode and write a signed integer (from a bigint)
The number to encode
How many bytes to make the encoded value
How many bytes were written (Same as bytes parameter)
Encode and write a signed integer (one byte)
The number to encode
How many bytes were written (1)
Encode and write signed integers (one byte)
The numbers to encode
How many bytes were written (Same as values.length)
Encode and write a signed one's complement
The number to encode
How many bytes to make the encoded value
How many bytes were written (Same as bytes parameter if provided)
Encode and write a signed ones complement (from a bigint)
The number to encode
How many bytes to make the encoded value
How many bytes were written (Same as bytes parameter)
Encode and write a signed ones complement (one byte)
The number to encode
How many bytes were written (1)
Encode and write a signed ones complements
The numbers to encode
How many bytes were written (Same as values.length)
Write a utf8 string to the buffer
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.
How many bytes were written
Write a twos complement to the buffer
The number to encode
How long the twos complement to be written is in bytes
How many bytes were written (Same as bytes parameter if provided)
Write a twos complement to the buffer (From a bigint)
The number to encode
How long the twos complement to be written is in bytes
How many bytes were written (Same as bytes parameter)
Write a twos complement to the buffer (one byte)
The number to encode
How many bytes were written (1)
Write twos complements to the buffer (one byte each)
The numbers to encode
How many bytes were written (Same as values.length)
Write a Uint8Array to the buffer (first byte first written to the end[BE])
Write a Uint8Array to the buffer backward (last byte first written to the end[LE])
Write an unsigned integer to the buffer
The unsigned int to write
How many bytes the unsined int is (If not provided, it will write the minimum length)
How many bytes were written (Same as bytes parameter if provided)
Write an unsigned integer to the buffer
The unsigned int to write (a bigint)
How many bytes the unsined int is (If not provided, it will write the minimum length)
How many bytes were written (Same as bytes parameter)
Write a writeable buffer storing data to the buffer
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, usewritableStream
instead.