guess-api-charset

guess api charset if it is not given.

guess-api-charset

Guessing api charset.

var guessapi = require('./');
var fs = require('fs')
 
 
var guessapi = guessapi("http://localhost:3000/nonhead", cb);
 
function cb(encodingbuf) {
  // result: 
  // { charset: 'utf-8' } <Buffer 66 69 65 6c 64 31 2c 66 69 65 6c 64 32 2c 66 69 65 6c 64 33 0a 31 2c 32 2c 33> 
  // if it can find charset in header it will return charset by http reponse's header charset value. 
 
  console.log(encoding, buf)
}
 
guessapi;

Only read the first chunk (why read only the first chunk? cause will reduce lot of time of guessing super large data), and guess the encoding by using the first chunk.

MIT