fetch icon indicating copy to clipboard operation
fetch copied to clipboard

readBlobAsText does not repect the reponse charset

Open joe06102 opened this issue 4 years ago • 2 comments

I'm working on a react-native project which is dependent of this lib. But I found the readBlobAsText does not respect the charset in Content-Type, which throws error when the charset is not utf8-encoded.

the problematic code below:

function readBlobAsText(blob) {
  var reader = new FileReader()
  var promise = fileReaderReady(reader)
  reader.readAsText(blob) // <-- FilerReader accept a second param 'encode', which can be retrieved from the response header.
  return promise
}

And here is my code suggestion:

  function getEncode() {
    const contentType = xhr.getResponseHeader('content-type')
    return /charset=([A-Za-z0-9_\-]+)/.exec(contentType)?.[1] || 'utf-8'
  }

joe06102 avatar Oct 15 '21 02:10 joe06102

is this repo dead?

joe06102 avatar Oct 18 '21 09:10 joe06102

Hi, no, it is still maintained

JakeChampion avatar Oct 18 '21 12:10 JakeChampion