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

guess-api-charset

guess-api-charset

Guessing api charset.

Example

var guessapi = require('./');
var fs = require('fs')
 
 
var guessapi = guessapi("http://localhost:3000/nonhead", cb);
 
function cb(encoding, buf) {
  // 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;

How it work?

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.

License

MIT