chardet

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.

Installation

npm i chardet

Usage

var chardet =require('chardet');

chardet.detect(newBuffer('hello there!'));

// or

chardet.detectFile('/path/to/file',function(err,encoding){});

// or

chardet.detectFileSync('/path/to/file');

Working with large data sets

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: