The bytes to decode, e.g. the data from a "data" event.
Optionallossy: boolean
true to replace invalid or incomplete UTF-8 with the replacement character (U+FFFD) instead of returning null. Defaults to false.
The text, or null if the bytes aren't valid UTF-8 (including when they end part-way through a character) and lossy isn't true.
Decodes bytes as UTF-8 text.
Data from
readBytes()orreadAvailable()can end part-way through a multi-byte character, whose remaining bytes arrive in the next read. Such bytes aren't valid UTF-8 on their own, so join the reads' bytes before decoding them, or usereadUntil()with a delimiter, whose data always ends with a complete character.