new RandomAccessFile(file, endian)
Store a buffer or string and add functionality for random access
Unless otherwise noted all read functions advance the file's pointer by the length of the data read
Parameters:
| Name | Type | Description |
|---|---|---|
file |
Buffer | string | A file as a string or Buffer to load for random access |
endian |
number | Endianess of the file constants BIG_ENDIAN and LITTLE_ENDIAN are provided |
Methods
-
getLength()
-
Get buffer length
Returns:
- Type
- number
-
getPos()
-
Get current position in the file
Returns:
- Type
- number
-
read(length)
-
Read a set number of bytes from the buffer
Parameters:
Name Type Default Description lengthnumber 1 Number of bytes to read Returns:
number if length = 1, otherwise number[]- Type
- number | Array.<number>
-
readByte()
-
Read a single byte from the buffer
Returns:
- Type
- number
-
readFloat()
-
Read a float from the buffer
Returns:
- Type
- number
-
readInt()
-
Read a 4-byte unsigned integer from the buffer
Returns:
- Type
- number
-
readShort()
-
Read a 2-byte unsigned integer from the buffer
Returns:
- Type
- number
-
readSignedInt()
-
Read a 2-byte signed integer from the buffer
Returns:
- Type
- number
-
readString(length)
-
Read a string of a specificed length from the buffer
Parameters:
Name Type Description lengthnumber Length of string to read Returns:
- Type
- string
-
seek(position)
-
Seek to a provided buffer offset
Parameters:
Name Type Description positionnumber Byte offset -
skip(length)
-
Advance the pointer forward a set number of bytes
Parameters:
Name Type Description lengthnumber Number of bytes to skip