Reads at least bytes from @io, but will read up 10 bytes ahead if needed to ensure the data read is valid in the ecoding of that data. This should ensure that it is safe to use regular expressions on the read data, unless it is actually a broken encoding. The read data will be returned in @encoding.
# File lib/csv.rb, line 2266 def read_to_char(bytes) return "" if @io.eof? data = read_io(bytes) begin raise unless data.valid_encoding? encoded = encode_str(data) raise unless encoded.valid_encoding? return encoded rescue # encoding error or my invalid data raise if @io.eof? or data.size >= bytes + 10 return data else data += read_io(1) retry end end end