Function: readUtf8()
ts
function readUtf8(cursor, length): string;Defined in: cursor/readUtf8.ts:23
Reads UTF-8 text of a number of bytes, with no terminator.
The function decodes every byte of the length, null bytes included. The result for bytes that are not valid UTF-8 depends on the environment.
Parameters
cursor
The cursor to read from. The function moves the cursor past the bytes.
length
number
The number of bytes. A length of 0 reads an empty string.
Returns
string
The text.
Throws
RangeError if length is negative or the bytes pass cursor.end.
Example
ts
const cursor = cursorOf([0xc3, 0xa9, 0x61])
const text = readUtf8(cursor, 2) // 'é'