readStringWithLength method

String readStringWithLength(
  1. int length
)

Reads length bytes and decodes them as UTF-8, allowing malformed sequences (invalid bytes become U+FFFD) rather than throwing.

Unlike readString, this does NOT enforce strict UTF-8. It is intended for Luau console spans, where a framing desync can leave a byte range that isn't valid UTF-8; tolerating that keeps a bad span from crashing the VM. Do not use it for data where malformed bytes should signal corruption — prefer readString there.

Implementation

String readStringWithLength(int length) =>
    _utf8DecoderLossy.convert(read(length, false));