runk / node-chardet

Character encoding detection tool for NodeJS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feature request

hjy1210 opened this issue · comments

It seems chardet can only be used in Node environment.

Hope chardet support client-side javascript.

In other words, hope it can be used with FileReader.

Now I know the solution.

Assume file is one of the drop file, reader is an instance of FileReader,

  1. use reader.readAsArrayBuffer(file) to get ArrayBuffer, named arraybuf.
  2. use var enc=chardet.detect(new Buffer(arraybuf)) to detect the encoding as enc.
  3. use reader.readAsText(file,enc) to extract the contents of the file.

Thanks for your package.

Closing it as stale.