lihai 8d6c751f49 feat: push | hace 2 años | |
---|---|---|
.. | ||
encoding | hace 2 años | |
.npmignore | hace 2 años | |
.travis.yml | hace 2 años | |
LICENSE | hace 2 años | |
README.md | hace 2 años | |
index.js | hace 2 años | |
match.js | hace 2 años | |
package.json | hace 2 años | |
yarn.lock | hace 2 años |
Chardet is a character detection module for NodeJS written in pure Javascript. Module is based on ICU project http://site.icu-project.org/, which uses character occurency analysis to determine the most probable encoding.
npm i chardet
var chardet = require('chardet');
chardet.detect(new Buffer('hello there!'));
// or
chardet.detectFile('/path/to/file', function(err, encoding) {});
// or
chardet.detectFileSync('/path/to/file');
Sometimes, when data set is huge and you want to optimize performace (in tradeoff of less accuracy), you can sample only first N bytes of the buffer:
chardet.detectFile('/path/to/file', { sampleSize: 32 }, function(err, encoding) {});
Currently only these encodings are supported, more will be added soon.