README.md~ 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. iconv-lite - native javascript conversion between character encodings.
  2. ======================================================================
  3. ## Usage
  4. var iconv = require('iconv-lite');
  5. // Convert from an encoded buffer to string.
  6. str = iconv.fromEncoding(buf, 'win-1251');
  7. // Or
  8. str = iconv.decode(buf, 'win-1251');
  9. // Convert from string to an encoded buffer.
  10. buf = iconv.toEncoding("Sample input string", 'win-1251');
  11. // Or
  12. buf = iconv.encode("Sample input string", 'win-1251');
  13. ## Supported encodings
  14. Currently only a small part of encodings supported:
  15. * All node.js native encodings: 'utf8', 'ucs2', 'ascii', 'binary', 'base64'.
  16. * 'latin1'
  17. * Cyrillic encodings: 'windows-1251', 'koi8-r', 'iso 8859-5'.
  18. Other encodings are easy to add, see the source. Please, participate.
  19. ## Encoding/decoding speed
  20. Comparison with iconv module (1000 times 256kb, on Core i5/2.5 GHz).
  21. Operation\module iconv iconv-lite (this)
  22. toEncoding('win1251') 19.57 mb/s 49.04 mb/s
  23. fromEncoding('win1251') 16.39 mb/s 24.11 mb/s
  24. ## Notes
  25. This module is JavaScript-only, thus can be used in a sandboxed environment like [Cloud9](http://c9.io).
  26. Untranslatable characters are set to '?'. No transliteration is currently supported, pull requests are welcome.
  27. ## Testing
  28. npm install --dev iconv-lite
  29. vows
  30. ## TODO
  31. * Support streaming character conversion, something like util.pipe(req, iconv.fromEncodingStream('latin1')).
  32. * Add more encodings.
  33. * Add transliteration (best fit char).
  34. * Add tests and correct support of variable-byte encodings (currently work is delegated to node).