When a server sends UTF-8 bytes, how do you read them without characters becoming pure bytes? (\x40 etc)
When a server sends UTF-8 bytes, how do you read them without characters becoming
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I believe
read_nonblockusesread, which in turn says:Which means you don’t need to specify
IO#set_encoding, but that you can, after you read whole string, force its encoding (usingString#force_encoding!) toUTF-8.I emphasized ‘whole’, as you need to make sure that you read entire Unicode character at the end of the string, as if only part of it is read, you will get invalid UTF-8 character and Ruby might complain about it further down the line.