npm install two more modules: buffer and stream).var iconv = ; // Convert from an encoded buffer to js string.str = iconv; // Convert from js string to an encoded buffer.buf = iconv; // Check if encoding is supportediconv // Decode stream (from binary stream to js strings)http; // Convert encoding streaming examplefs ; // Sugar: all encode/decode streams have .collect(cb) method to accumulate data.http;NOTE: This doesn't work on latest Node versions. See details.
// After this call all Node basic primitives will understand iconv-lite encodings.iconv; // Examples:buf = str 'win1251';buf;str = buf;;Buffer; http; fs; // External modules are also supported (if they use Node primitives, which they probably do).request = ;; // To remove extensionsiconv;See all supported encodings on wiki.
Most singlebyte encodings are generated automatically from node-iconv. Thank you Ben Noordhuis and libiconv authors!
Multibyte encodings are generated from Unicode.org mappings and WHATWG Encoding Standard mappings. Thank you, respective authors!
Comparison with node-iconv module (1000x256kb, on MacBook Pro, Core i5/2.6 GHz, Node v0.12.0). Note: your results may vary, so please always check on your hardware.
operation [email protected] [email protected]
----------------------------------------------------------
encode('win1251') ~96 Mb/s ~320 Mb/s
decode('win1251') ~95 Mb/s ~246 Mb/s
stripBOM: false in options
(f.ex. iconv.decode(buf, enc, {stripBOM: false})).
A callback might also be given as a stripBOM parameter - it'll be called if BOM character was actually found.addBOM: true option.This library supports UTF-16LE, UTF-16BE and UTF-16 encodings. First two are straightforward, but UTF-16 is trying to be smart about endianness in the following ways:
defaultEncoding: 'utf-16be' option. Strips BOM unless stripBOM: false.addBOM: false to override.When decoding, be sure to supply a Buffer to decode() method, otherwise bad things usually happen.
Untranslatable characters are set to � or ?. No transliteration is currently supported.
Node versions 0.10.31 and 0.11.13 are buggy, don't use them (see #65, #77).
$ git clone [email protected]:ashtuchkin/iconv-lite.git$ cd iconv-lite$ npm install$ npm test $ # To view performance: $ node test/performance.js $ # To view test coverage: $ npm run coverage$ open coverage/lcov-report/index.html