If I pass bytes that are invalid UTF-8 to Node and try to read them from process.argv
, I get the replacement character (U+FFFD
)
$ node -e "console.log(process.argv[1].codePointAt(0).toString(16))" $'\x7f'
7f
$ node -e "console.log(process.argv[1].codePointAt(0).toString(16))" $'\x80'
fffd
whereas command line tools implemented in C get the raw bytes
$ echo -n $'\x7f' | xxd
00000000: 7f .
$ echo -n $'\x80' | xxd
00000000: 80 .
Is there a way to get the raw bytes of the arguments that were passed in to my Node program without having Node try to decode them as a UTF-8 string?