I have an ArrayBuffer
which contains a string encoded using UTF-8 and I can't find a standard way of converting such ArrayBuffer
into a JS String
(which I understand is encoded using UTF-16).
I've seen this code in numerous places, but I fail to see how it would work with any UTF-8 code points that are longer than 1 byte.
return String.fromCharCode.apply(null, new Uint8Array(data));
Similarly, I can't find a standard way of converting from a String
to a UTF-8 encoded ArrayBuffer
.
var uintArray = new Uint8Array("string".split('').map(function(char) {return char.charCodeAt(0);}));
– Loanloandanew Uint8Array("h€l".split('').map(function(char) {return char.charCodeAt(0);}));
and it returned an array with 3 bytes, however I believe it should be 5 bytes because occording to fileformat.info/info/unicode/char/20ac/index.htm it says the UTF-8 encoding of it is0xE2 0x82 0xAC
. – Photosynthesis