guess-api-charset

0.2.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i guess-api-charset

Weekly Downloads

1

Version

0.2.0

License

MIT

Last publish

Collaborators

  • chilijung