Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1064

node.js Buffer latin1 encoding for characters out of range

$
0
0

I'm trying to understand the implementation of the latin1 encoding in the node.js Buffer implementation.In latin1, each character is represented by 1 byte.

When I try to encode a character that lies outside of the range, for example 😎:

Buffer.alloc(4, "😎", "latin1")

I get this buffer:

<Buffer 3d 0e 3d 0e>

I was expecting some kind of encoding error instead.Those bytes aren't even the UTF-8 encoding, which would be <Buffer f0 9f 98 08>

Does anyone have an idea how node.js handles these out of range cases?The node version is 18.19.0.

Thanks!


Viewing all articles
Browse latest Browse all 1064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>