new RandomAccessFile(file, endian)
Store a array 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 |
Uint8Array | string | A file as a string or Uint8Array to load for random access |
endian |
number | Endianess of the file constants BIG_ENDIAN and LITTLE_ENDIAN are provided |
Methods
-
getLength()
-
Get array length
Returns:
- Type
- number
-
getPos()
-
Get current position in the file
Returns:
- Type
- number
-
read(length)
-
Read a set number of bytes from the array
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 array
Returns:
- Type
- number
-
readFloat()
-
Read a float from the array
Returns:
- Type
- number
-
readInt()
-
Read a 4-byte unsigned integer from the array
Returns:
- Type
- number
-
readShort()
-
Read a 2-byte unsigned integer from the array
Returns:
- Type
- number
-
readSignedInt()
-
Read a 2-byte signed integer from the array
Returns:
- Type
- number
-
readSInt4()
-
Read a 4-byte signed integer from the array
Returns:
- Type
- number
-
readString(length)
-
Read a string of a specificed length from the array
Parameters:
Name Type Description lengthnumber Length of string to read Returns:
- Type
- string
-
seek(position)
-
Seek to a provided array 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