I’m trying to port some code from Java to Node.js, and I’ve run into a little trouble.
Given the String "645553dd" in Java, I can extract a series of bytes using .getBytes("ISO_8859_1") that looks like { 54, 52, 53, 53, 53, 51, 100, 100 }. However, I’m having a hard time doing the same in Node.js. I tried using buffers, converting to the similar ASCII charset, but no luck. I tried using node-iconv, but it kept throwing the error EILSEQ, Illegal character sequence. How can I get the same set of bytes in Node.js?
You should be able to convert from the Buffer’s default encoding of
UTF-8toISO-8859-1withiconv:Note that the values are output in base-16 —
0x64 == 100:If you’re still getting a
EILSEQerror, then your strings contains a character code that isn’t supported byISO-8859-1. You’ll either have to translate or ignore these characters:Or try a different encoding, like UTF-8: