how does axios handle blob vs arraybuffer as responseType? how does axios handle blob vs arraybuffer as responseType? javascript javascript

how does axios handle blob vs arraybuffer as responseType?


From axios docs:

// `responseType` indicates the type of data that the server will respond with// options are: 'arraybuffer', 'document', 'json', 'text', 'stream'//   browser only: 'blob'responseType: 'json', // default

'blob' is a "browser only" option.

So from node.js, when you set responseType: "blob", "json"will actually be used, which I guess fallbacks to "text" when no parse-able JSON data has been fetched.

Fetching binary data as text is prone to generate corrupted data.Because the text returned by Body.text() and many other APIs are USVStrings (they don't allow unpaired surrogate codepoints ) and because the response is decoded as UTF-8, some bytes from the binary file can't be mapped to characters correctly and will thus be replaced by � (U+FFDD) replacement character, with no way to get back what that data was before: your data is corrupted.

Here is a snippet explaining this, using the header of a .png file 0x89 0x50 0x4E 0x47 as an example.