node package manager
Easy collaboration. Discover, share, and reuse code in your team. Create a free org »

guess-encoding

Guess encoding

Guess encoding in an super fast speed!

Install

npm install guess-encoding

Example

var guess = require('guess-encoding')
 
// first argument is the file you want to guess 
// and the callback function will pass the result of the guessing and second argument is the buffer :) 
var guess = guess('./test/100000.csv', cb);
 
function cb(encode, chunk) {
    console.log(encode)
    // result: 
    // { language: '', charset: 'UTF-8', confidence: 80 } 
    // { language: 'es', charset: 'ISO-8859-1', confidence: 30 } 
}
 
// start guessing 
guess;

How it work

Streaming the first chunk of data in memory and only detect for the first few buffer and detected the encoding. So this will work in super large files, cause we are not loading all the data from origin, only a few buffers :)

License

MIT