Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readBlobAsText does not repect the reponse charset #1059

Open
joe06102 opened this issue Oct 15, 2021 · 2 comments
Open

readBlobAsText does not repect the reponse charset #1059

joe06102 opened this issue Oct 15, 2021 · 2 comments

Comments

@joe06102
Copy link

@joe06102 joe06102 commented Oct 15, 2021

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
Copy link
Author

@joe06102 joe06102 commented Oct 18, 2021

is this repo dead?

@JakeChampion
Copy link
Collaborator

@JakeChampion JakeChampion commented Oct 18, 2021

Hi, no, it is still maintained

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@JakeChampion @joe06102 and others