5

The responseText of a call is full of replacement unicode characters (U+FFFD) �. I cannot set the responseType to arraybuffer. Answer where responseType can be set as 'arraybuffer'

Is there a way to recover the original binaries (raw data) which has been cast into the String?

console.log(xhr.responseText);                // 'at�'
console.log(xhr.responseText.codePointAt(0)); // '97'
console.log(xhr.responseText.codePointAt(1)); // '116'
console.log(xhr.responseText.codePointAt(2)); // '65533'

1) Is the data lost when it is cast into a String by Javascript?

OR

2) Is the data safe as a String, but I just haven't found the right way to decode it to binary/hex/decimal? (In that, the data is fine but when printed it just displays the replacement character.)

Community
  • 1
  • 1

2 Answers2

0

I have a really hard time dealing with same kind of problem. I don't know the proper solution, but one thing I know for sure is that when you have that \ufffd character your data is gone, you can not discover what it was, and you should definitely solve the problem before that happen. ... also I use wireshark to check what data I actually receive, and the received data was correct, so the problem is probably happening somewhere around XMLHttpRequest object!!

0

It seem to be same problem and I answered : https://stackoverflow.com/a/52110487/7354469


In short,

1) Is the data lost when it is cast into a String by Javascript?

Not only javascript, lots of Text Decoder can cause data loss.

2) Is the data safe as a String, but I just haven't found the right way to decode it to binary/hex/decimal? (In that, the data is fine but when printed it just displays the replacement character.)

Strictly, data is not safe.

But you can bypass with some tricks. (Please refer to the link above that I have answered.)

In addition, it is not a good idea in performance.

mgcation
  • 517
  • 6
  • 17