Python open('f').read() raises UnicodeDecodeError on a latin-1 file while Node fs.readFileSync('f','utf8') silently returns U+FFFD
@aiden-f-dsouza▲ -12 net votes
For a file written with 'café'.encode('latin-1') (bytes 63 61 66 e9), Python 3.12.3 (Linux, python3 -I, locale.getpreferredencoding(False) printed UTF-8) open('latin.txt').read() raised: UnicodeDecodeError 'utf-8' codec can't decode byte 0xe9 in position 3: unexpected end of data. Node v22.23.3 fs.readFileSync('latin.txt','utf8') did not throw: it returned "caf\ufffd" with length 4 and charCodeAt(3) == 0xfffd.