Classes
Members
bytesAvailable
Returns the number of bytes available from the current position in the buffer
- Source:
endian
Returns the byte order
- Source:
endian
Sets the byte order
- Source:
length
Returns the length of the buffer
- Source:
length
Sets the length of the buffer
- Source:
position
Returns the current position in the buffer
- Source:
position
Sets the current position in the buffer
- Source:
stream
Returns the whole buffer
- Source:
Methods
clear()
Clears the contents of the buffer and resets the position to 0
- Source:
(async) compress(algorithmopt)
Compresses the buffer
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
algorithm |
'zlib' | 'deflate' | 'gzip' | 'brotli' |
<optional> |
zlib | The algorithm to compress the buffer with |
- Source:
Throws:
-
The value must be a valid compression algorithm
- Type
- ReferenceError
readBoolean() → {boolean}
Reads a boolean based value from the buffer
- Source:
Returns:
The boolean based value
- Type
- boolean
readByte() → {number}
Reads a signed byte from the buffer
- Source:
Returns:
The signed byte
- Type
- number
readBytes(bytes, positionopt, lengthopt)
Reads the number of data bytes, specified by the 'length' parameter, from the buffer
The bytes are read into the DynBuffer object specified by the 'bytes' parameter
The bytes are written into the destination DynBuffer starting at the position specified by 'position'
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
bytes |
DynBuffer | The DynBuffer to read data into | ||
position |
number |
<optional> |
0 | The position at which the read data should be written |
length |
number |
<optional> |
0 | The number of bytes to read |
- Source:
Throws:
-
If the given length is greater than the amount of bytes available
- Type
- RangeError
readDouble() → {number}
Reads an IEEE 754 double-precision (64-bit) floating-point number from the buffer
- Source:
Returns:
The IEEE 754 double-precision (64-bit) floating-point number
- Type
- number
readFloat() → {number}
Reads an IEEE 754 single-precision (32-bit) floating-point number from the buffer
- Source:
Returns:
The IEEE 754 single-precision (32-bit) floating-point number
- Type
- number
readInt() → {number}
Reads a signed 32-bit integer from the buffer
- Source:
Returns:
The signed 32-bit integer
- Type
- number
readLong() → {bigint}
Reads a signed long from the buffer
- Source:
Returns:
The signed long
- Type
- bigint
readMultiByte(length, charSetopt) → {string}
Reads a multibyte string of specified length from the buffer using the specified character set
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
length |
number | The number of bytes to read | ||
charSet |
string |
<optional> |
utf8 | The character set to decode the value to |
Throws:
-
The character set must exist
- Type
- Error
Returns:
The multibyte string
- Type
- string
readShort() → {number}
Reads a signed 16-bit integer from the buffer
- Source:
Returns:
The signed 16-bit integer
- Type
- number
readUTF() → {string}
Reads a UTF-8 string from the buffer
- Source:
Returns:
The UTF-8 string
- Type
- string
readUTFBytes(length) → {string}
Reads a sequence of UTF-8 bytes, specified by the length parameter, from the buffer
Parameters:
| Name | Type | Description |
|---|---|---|
length |
number | The number of bytes to read |
- Source:
Returns:
The UTF-8 string
- Type
- string
readUnsignedByte() → {number}
Reads an unsigned byte from the buffer
- Source:
Returns:
The unsigned byte
- Type
- number
readUnsignedInt() → {number}
Reads an unsigned 32-bit integer from the buffer
- Source:
Returns:
The unsigned 32-bit integer
- Type
- number
readUnsignedLong() → {bigint}
Reads an unsigned long from the buffer
- Source:
Returns:
The unsigned long
- Type
- bigint
readUnsignedShort() → {number}
Reads an unsigned 16-bit integer from the buffer
- Source:
Returns:
The unsigned 16-bit integer
- Type
- number
toString(encodingopt, prettyHexopt) → {string}
Converts the buffer to string
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
encoding |
'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex' |
<optional> |
utf8 | The encoding set to encode the buffer to |
prettyHex |
boolean |
<optional> |
false | When using hex for encoding, define if the hex string is pretty (with spacing and formatted) or not |
- Source:
Returns:
The buffer represented as a string
- Type
- string
(async) uncompress(algorithmopt)
Decompresses the buffer
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
algorithm |
'zlib' | 'deflate' | 'gzip' | 'brotli' |
<optional> |
zlib | The algorithm to decompress the buffer with |
- Source:
Throws:
-
The value must be a valid compression algorithm
- Type
- ReferenceError
writeBoolean(value)
Writes a boolean based value
Parameters:
| Name | Type | Description |
|---|---|---|
value |
boolean | number | The boolean based value to write to the buffer |
- Source:
writeByte(value)
Writes a byte
Parameters:
| Name | Type | Description |
|---|---|---|
value |
number | The byte to write to the buffer |
- Source:
writeBytes(bytes, positionopt, lengthopt)
Writes a sequence of 'length' bytes from the specified buffer, 'bytes', starting 'position' (zero-based index) bytes
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
bytes |
DynBuffer | Buffer | The DynBuffer (or Buffer) to write the bytes from, and into the buffer | ||
position |
number |
<optional> |
0 | A zero-based index indicating the position into the array to begin writing |
length |
number |
<optional> |
0 | An unsigned integer indicating how far into the buffer to write |
- Source:
Throws:
-
If the given length is greater than the remaining space in the destination buffer
- Type
- RangeError
writeDouble(value)
Writes an IEEE 754 double-precision (64-bit) floating-point number
Parameters:
| Name | Type | Description |
|---|---|---|
value |
number | The IEEE 754 double-precision (64-bit) floating-point number to write to the buffer |
- Source:
writeFloat(value)
Writes an IEEE 754 single-precision (32-bit) floating-point number
Parameters:
| Name | Type | Description |
|---|---|---|
value |
number | The IEEE 754 single-precision (32-bit) floating-point number to write to the buffer |
- Source:
writeInt(value)
Writes a 32-bit signed integer
Parameters:
| Name | Type | Description |
|---|---|---|
value |
number | The 32-bit signed integer to write to the buffer |
- Source:
writeLong(value)
Writes a signed long
Parameters:
| Name | Type | Description |
|---|---|---|
value |
bigint | The signed long to write to the buffer |
- Source:
writeMultiByte(value, charSetopt, sourceopt)
Writes a multibyte string using the specified character set
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
value |
string | The multibyte string to write to the buffer | ||
charSet |
string |
<optional> |
utf8 | The character set to encode the value with |
source |
boolean |
<optional> |
false | An internal parameter used for writeUTF to write the length of the string |
Throws:
-
The character set must exist
- Type
- Error
writeShort(value)
Writes a 16-bit integer
Parameters:
| Name | Type | Description |
|---|---|---|
value |
number | The 16-bit integer to write to the buffer |
- Source:
writeUTF(value)
Writes a UTF-8 string
Parameters:
| Name | Type | Description |
|---|---|---|
value |
string | The UTF-8 string to write to the buffer |
- Source:
writeUTFBytes(value)
Writes a UTF-8 string but without the length of the string
Parameters:
| Name | Type | Description |
|---|---|---|
value |
string | The UTF-8 string to write to the buffer |
- Source:
writeUnsignedInt(value)
Writes an unsigned 32-bit integer
Parameters:
| Name | Type | Description |
|---|---|---|
value |
number | The unsigned 32-bit integer to write to the buffer |
- Source:
writeUnsignedLong(value)
Writes an unsigned long
Parameters:
| Name | Type | Description |
|---|---|---|
value |
bigint | The unsigned long to write to the buffer |
- Source: