Read at most Length characters from Stream and return them in the string String. If Length is unbound, Stream is read to the end and Length is unified with the number of characters read.
I want to double check here since character encoding can get slippery.
The “… at most Length characters…” means “… at most Length Unicode code points…” that are read from Stream, right?
Edit: Assuming the answer is yes: Is there a predicate like read_string that will read N bytes from a stream and convert to a string?
Now, if you need to read JSON, a Prolog term or something else you can directly read from a stream you do not need the intermediate string. This is used to deal with Content-Length: Bytes in HTTP streams.
Without going too deep, a byte is 8 bits, so the largest integer you can represent with a byte is 256. In your example, the code 8594 cannot be a byte.