
\begin{DoxyItemize}
\item Doesn\textquotesingle{}t need native code compilation. Works on Windows and in sandboxed environments like \href{http://c9.io}{\texttt{ Cloud9}}.
\item Used in popular projects like \href{https://github.com/expressjs/body-parser}{\texttt{ Express.\+js (body\+\_\+parser)}}, \href{http://gruntjs.com/}{\texttt{ Grunt}}, \href{http://www.nodemailer.com/}{\texttt{ Nodemailer}}, \href{http://yeoman.io/}{\texttt{ Yeoman}} and others.
\item Faster than \href{https://github.com/bnoordhuis/node-iconv}{\texttt{ node-\/iconv}} (see below for performance comparison).
\item Intuitive encode/decode API
\item Streaming support for Node v0.\+10+
\item \mbox{[}Deprecated\mbox{]} Can extend Node.\+js primitives (buffers, streams) to support all iconv-\/lite encodings.
\item In-\/browser usage via \href{https://github.com/substack/node-browserify}{\texttt{ Browserify}} ($\sim$180k gzip compressed with Buffer shim included).
\item Typescript \href{https://github.com/ashtuchkin/iconv-lite/blob/master/lib/index.d.ts}{\texttt{ type definition file}} included.
\item React Native is supported (need to explicitly {\ttfamily npm install} two more modules\+: {\ttfamily buffer} and {\ttfamily stream}).
\item License\+: MIT.
\end{DoxyItemize}

\href{https://npmjs.org/packages/iconv-lite/}{\texttt{ }}\hypertarget{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10076}{}\doxysection{Usage}\label{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10076}
\hypertarget{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10077}{}\doxysubsection{Basic API}\label{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10077}

\begin{DoxyCode}{0}
\DoxyCodeLine{var iconv = require('iconv-\/lite');}
\DoxyCodeLine{}
\DoxyCodeLine{// Convert from an encoded buffer to js string.}
\DoxyCodeLine{str = iconv.decode(Buffer.from([0x68, 0x65, 0x6c, 0x6c, 0x6f]), 'win1251');}
\DoxyCodeLine{}
\DoxyCodeLine{// Convert from js string to an encoded buffer.}
\DoxyCodeLine{buf = iconv.encode("{}Sample input string"{}, 'win1251');}
\DoxyCodeLine{}
\DoxyCodeLine{// Check if encoding is supported}
\DoxyCodeLine{iconv.encodingExists("{}us-\/ascii"{}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10078}{}\doxysubsection{Streaming API (\+Node v0.\+10+)}\label{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10078}

\begin{DoxyCode}{0}
\DoxyCodeLine{// Decode stream (from binary stream to js strings)}
\DoxyCodeLine{http.createServer(function(req, res) \{}
\DoxyCodeLine{    var converterStream = iconv.decodeStream('win1251');}
\DoxyCodeLine{    req.pipe(converterStream);}
\DoxyCodeLine{}
\DoxyCodeLine{    converterStream.on('data', function(str) \{}
\DoxyCodeLine{        console.log(str); // Do something with decoded strings, chunk-\/by-\/chunk.}
\DoxyCodeLine{    \});}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{// Convert encoding streaming example}
\DoxyCodeLine{fs.createReadStream('file-\/in-\/win1251.txt')}
\DoxyCodeLine{    .pipe(iconv.decodeStream('win1251'))}
\DoxyCodeLine{    .pipe(iconv.encodeStream('ucs2'))}
\DoxyCodeLine{    .pipe(fs.createWriteStream('file-\/in-\/ucs2.txt'));}
\DoxyCodeLine{}
\DoxyCodeLine{// Sugar: all encode/decode streams have .collect(cb) method to accumulate data.}
\DoxyCodeLine{http.createServer(function(req, res) \{}
\DoxyCodeLine{    req.pipe(iconv.decodeStream('win1251')).collect(function(err, body) \{}
\DoxyCodeLine{        assert(typeof body == 'string');}
\DoxyCodeLine{        console.log(body); // full request body string}
\DoxyCodeLine{    \});}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10079}{}\doxysubsection{\mbox{[}\+Deprecated\mbox{]} Extend Node.\+js own encodings}\label{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10079}
\begin{quote}
NOTE\+: This doesn\textquotesingle{}t work on latest Node versions. See \href{https://github.com/ashtuchkin/iconv-lite/wiki/Node-v4-compatibility}{\texttt{ details}}. \end{quote}

\begin{DoxyCode}{0}
\DoxyCodeLine{// After this call all Node basic primitives will understand iconv-\/lite encodings.}
\DoxyCodeLine{iconv.extendNodeEncodings();}
\DoxyCodeLine{}
\DoxyCodeLine{// Examples:}
\DoxyCodeLine{buf = new Buffer(str, 'win1251');}
\DoxyCodeLine{buf.write(str, 'gbk');}
\DoxyCodeLine{str = buf.toString('latin1');}
\DoxyCodeLine{assert(Buffer.isEncoding('iso-\/8859-\/15'));}
\DoxyCodeLine{Buffer.byteLength(str, 'us-\/ascii');}
\DoxyCodeLine{}
\DoxyCodeLine{http.createServer(function(req, res) \{}
\DoxyCodeLine{    req.setEncoding('big5');}
\DoxyCodeLine{    req.collect(function(err, body) \{}
\DoxyCodeLine{        console.log(body);}
\DoxyCodeLine{    \});}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{fs.createReadStream("{}file.txt"{}, "{}shift\_jis"{});}
\DoxyCodeLine{}
\DoxyCodeLine{// External modules are also supported (if they use Node primitives, which they probably do).}
\DoxyCodeLine{request = require('request');}
\DoxyCodeLine{request(\{}
\DoxyCodeLine{    url: "{}http://github.com/"{}, }
\DoxyCodeLine{    encoding: "{}cp932"{}}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{// To remove extensions}
\DoxyCodeLine{iconv.undoExtendNodeEncodings(); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10080}{}\doxysection{Supported encodings}\label{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10080}

\begin{DoxyItemize}
\item All node.\+js native encodings\+: utf8, ucs2 / utf16-\/le, ascii, binary, base64, hex.
\item Additional unicode encodings\+: utf16, utf16-\/be, utf-\/7, utf-\/7-\/imap.
\item All widespread singlebyte encodings\+: Windows 125x family, ISO-\/8859 family, IBM/\+DOS codepages, Macintosh family, KOI8 family, all others supported by iconv library. Aliases like \textquotesingle{}latin1\textquotesingle{}, \textquotesingle{}us-\/ascii\textquotesingle{} also supported.
\item All widespread multibyte encodings\+: CP932, CP936, CP949, CP950, GB2312, GBK, GB18030, Big5, Shift\+\_\+\+JIS, EUC-\/\+JP.
\end{DoxyItemize}

See \href{https://github.com/ashtuchkin/iconv-lite/wiki/Supported-Encodings}{\texttt{ all supported encodings on wiki}}.

Most singlebyte encodings are generated automatically from \href{https://github.com/bnoordhuis/node-iconv}{\texttt{ node-\/iconv}}. Thank you Ben Noordhuis and libiconv authors!

Multibyte encodings are generated from \href{http://www.unicode.org/Public/MAPPINGS/}{\texttt{ Unicode.\+org mappings}} and \href{http://encoding.spec.whatwg.org/}{\texttt{ WHATWG Encoding Standard mappings}}. Thank you, respective authors!\hypertarget{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10081}{}\doxysection{Encoding/decoding speed}\label{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10081}
Comparison with node-\/iconv module (1000x256kb, on Mac\+Book Pro, Core i5/2.\+6 GHz, Node v0.\+12.\+0). Note\+: your results may vary, so please always check on your hardware. \begin{DoxyVerb}operation             iconv@2.1.4   iconv-lite@0.4.7
----------------------------------------------------------
encode('win1251')     ~96 Mb/s      ~320 Mb/s
decode('win1251')     ~95 Mb/s      ~246 Mb/s
\end{DoxyVerb}
 \hypertarget{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10082}{}\doxysection{BOM handling}\label{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10082}

\begin{DoxyItemize}
\item Decoding\+: BOM is stripped by default, unless overridden by passing {\ttfamily strip\+BOM\+: false} in options (f.\+ex. {\ttfamily iconv.\+decode(buf, enc, \{strip\+BOM\+: false\})}). A callback might also be given as a {\ttfamily strip\+BOM} parameter -\/ it\textquotesingle{}ll be called if BOM character was actually found.
\item If you want to detect UTF-\/8 BOM when decoding other encodings, use \href{https://github.com/danielgindi/node-autodetect-decoder-stream}{\texttt{ node-\/autodetect-\/decoder-\/stream}} module.
\item Encoding\+: No BOM added, unless overridden by {\ttfamily add\+BOM\+: true} option.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10083}{}\doxysection{UTF-\/16 Encodings}\label{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10083}
This library supports UTF-\/16\+LE, UTF-\/16\+BE and UTF-\/16 encodings. First two are straightforward, but UTF-\/16 is trying to be smart about endianness in the following ways\+:
\begin{DoxyItemize}
\item Decoding\+: uses BOM and \textquotesingle{}spaces heuristic\textquotesingle{} to determine input endianness. Default is UTF-\/16\+LE, but can be overridden with `default\+Encoding\+: \textquotesingle{}utf-\/16be'{\ttfamily option. Strips BOM unless}strip\+BOM\+: false{\ttfamily .}
\item {\ttfamily Encoding\+: uses UTF-\/16\+LE and writes BOM by default. Use}add\+BOM\+: false\`{} to override.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10084}{}\doxysection{Other notes}\label{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10084}
When decoding, be sure to supply a Buffer to decode() method, otherwise \href{https://github.com/ashtuchkin/iconv-lite/wiki/Use-Buffers-when-decoding}{\texttt{ bad things usually happen}}. ~\newline
 Untranslatable characters are set to {\ucr} or ?. No transliteration is currently supported. ~\newline
 Node versions 0.\+10.\+31 and 0.\+11.\+13 are buggy, don\textquotesingle{}t use them (see \#65, \#77). ~\newline
\hypertarget{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10085}{}\doxysection{Testing}\label{md_sfcode_node_modules_external_editor_node_modules_iconv_lite_README_autotoc_md10085}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ git clone git@github.com:ashtuchkin/iconv-\/lite.git}
\DoxyCodeLine{\$ cd iconv-\/lite}
\DoxyCodeLine{\$ npm install}
\DoxyCodeLine{\$ npm test}
\DoxyCodeLine{    }
\DoxyCodeLine{\$ \# To view performance:}
\DoxyCodeLine{\$ node test/performance.js}
\DoxyCodeLine{}
\DoxyCodeLine{\$ \# To view test coverage:}
\DoxyCodeLine{\$ npm run coverage}
\DoxyCodeLine{\$ open coverage/lcov-\/report/index.html }

\end{DoxyCode}
 