Creates a new BinaryWriter with empty writing buffer.
Optionalendianness: EndiannessDefaults to Little Endian.
Creates a new BinaryWriter and fills its buffer with the specified
array. Position is set to the end of the buffer, meaning
any subsequent writes will append new data at the end.
Optionalendianness: EndiannessDefaults to Little Endian.
There is no syncing between the buffer and the passed array, changes to either won't be reflected in the other.
OutOfBoundsError Thrown when any of the array elements provided is outside byte range
Creates a new BinaryWriter and fills its buffer with the contents of
the array. Position is set to the end of the buffer, meaning
any subsequent writes will append new data at the end.
Optionalendianness: EndiannessDefaults to Little Endian.
Length of the written data in bytes
Current position inside the buffer denoting the place at which the next write operation will happen.
Changes the position inside the buffer at which the next write operation
will happen. Setting it to less than 0 will clamp it to 0, and setting it
to anything more than length will clamp it to length.
Completely clears the underlying buffer and changes position and length to zero.
Returns the contents of the writer as regular array of bytes.
Returns the contents of the writer as Uint8Array
Writes one byte, 0x01 for true and 0x00 for false and advances
the position by one byte.
Boolean to write.
Writes one byte and advances the position by one byte.
Byte to write.
OutOfBoundsError Thrown when value is less than 0, more
than 255, +/- infinity or NaN.
Writes the passed array of bytes and advances the position by bytes's length.
Bytes to write.
OutOfBoundsError Thrown when any of the bytes in bytes is less
than 0, more than 255, +/- infinity or NaN.
Writes a single character in the specified encoding and advances the position by the number of bytes the character takes in that encoding.
Unicode codepoint of the character to write or a string, in which case only the first character is used.
Character encoding to use when writing the character.
InvalidArgumentError Thrown when null is passed for character
or when the codepoint passed in character is negative, +/- infinite or NaN
EncodingError Thrown when unknown or unsupported encoding is passed.
Writes multiple characters in the specified encoding and advances the position by the number of bytes the characters take in that encoding.
Unicode codepoints of the character to write or a string.
Character encoding to use when writing the characters.
InvalidArgumentError Thrown when null is passed for character
or when any of the codepoints passed in characters is negative, +/- infinite or NaN
EncodingError Thrown when unknown or unsupported encoding is passed.
Writes a double and advances the position by eight bytes.
Double to write.
Writes a float and advances the position by four bytes.
Float to write.
OutOfBoundsError Thrown when value is less than -3.4028235e+38 or more than 3.4028235e+38.
Writes an int and advances the position by four bytes.
Int to write.
OutOfBoundsError Thrown when value is less than
-2,147,483,648 more than 2,147,483,647, +/- infinity or NaN.
Writes a long and advances the position by eight bytes.
Long to write accepted both as a string (for 100% precision in very low/high numbers) and number, when precision is not a requirement.
JavaScript internally uses double to represent all numbers.
The smallest and largest number that can be represented without loss of
precision are, respectively, −9,007,199,254,740,991 −(2^53 − 1) and
9,007,199,254,740,991 2^53 − 1, while long can hold values between
-2^63 and 2^63 - 1, while unsigned long
goes all the way up to 2^64-1.
What happens when you go beyond those limits is that some numbers just
cannot be expressed. 9007199254740992+1 is the same as
9007199254740992+1+1+1+1 and if you try to set a variable to
9007199254740993 it just gets rounded down.
InvalidArgumentError Thrown when value is NaN or +/- infinite.
OutOfBoundsError Thrown when value is less than -9,223,372,036,854,775,808 more than 9,223,372,036,854,775,807 +/- infinity or NaN.
Writes the same byte multiple times and advances the position by repeats bytes.
Byte to write.
Number of times to write the byte.
InvalidArgumentError Thrown when repeats is less than 0, +/- infinity or NaN.
OutOfBoundsError Thrown when value is less than 0, more than 255, +/- infinity or NaN.
Writes a short and advances the position by two bytes.
Short to write.
OutOfBoundsError Thrown when value is less than -32,768
more than 32,767, +/- infinity or NaN.
Writes a signed byte and advances the position by one byte.
Signed byte to write.
OutOfBoundsError Thrown when value is less than -128, more
than 127, +/- infinity or NaN.
Writes length-prefixed multiple characters in the specified encoding and advances the position by the number of bytes the characters take in that encoding.
Unicode codepoints of the character to write or a string.
Character encoding to use when writing the characters.
InvalidArgumentError Thrown when null is passed for character
or when any of the codepoints passed in characters is negative, +/- infinite or NaN
EncodingError Thrown when unknown or unsupported encoding is passed.
Writes an unsigned int and advances the position by four bytes.
Unsigned int to write.
OutOfBoundsError Thrown when value is less than 0 more than
4,294,967,295 +/- infinity or NaN.
Writes an unsigned long and advances the position by eight bytes. See the remark in writeLong for details about why strings are preferred.
Unsigned long to write accepted both as a string (for 100% precision in very low/high numbers) and number, when precision is not a requirement.
InvalidArgumentError Thrown when value is NaN or +/- infinite.
OutOfBoundsError Thrown when value is less than 0 more than 18,446,744,073,709,551,615 +/- infinity or NaN.
Writes an unsigned short and advances the position by two bytes.
Unsigned short to write.
OutOfBoundsError Thrown when value is less than 0 more than
65,535, +/- infinity or NaN.
A binary stream writer compatible with majority of methods in C#'s BinaryWriter.
All write operations advance the position by the number of bytes that were written.
Any time the word stream or buffer is used in the documentation it refers to the internal array that represents the written data.