Text mode descriptors behave strangely under various text encodings. Maybe it would be more reliable if we opened files in binary mode instead.