How to use iconv-lite

Comprehensive iconv-lite code examples:

How to use iconv-lite.decodeStream:

1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
    return;
  }
  charset = !buffer || isUtf8(buffer) ? 'utf8' : 'GB18030';
}
if (!iconvDecoder) {
  iconvDecoder = iconv.decodeStream(charset);
  next(iconvDecoder);
}
if (buffer) {
  iconvDecoder.write(buffer);

How to use iconv-lite.getDecoder:

40
41
42
43
44
45
46
47
48
49
50
51


function getDecoder (encoding) {
  if (!encoding) return null


  try {
    return iconv.getDecoder(encoding)
  } catch (e) {
    // error getting decoder
    if (!ICONV_ENCODING_MESSAGE_REGEXP.test(e.message)) throw e

How to use iconv-lite.encode:

627
628
629
630
631
632
633
634
635
636
st.equal(qs.stringify({ 県: '大阪府', '': '' }, {
    encoder: function (str) {
        if (str.length === 0) {
            return '';
        }
        var buf = iconv.encode(str, 'shiftjis');
        var result = [];
        for (var i = 0; i < buf.length; ++i) {
            result.push(buf.readUInt8(i).toString(16));
        }

How to use iconv-lite.decode:

195
196
197
198
199
200
201
202
203
204
	}
	else if (!iconv.encodingExists(charset)) {
		Zotero.debug(`Unknown charset ${charset} -- decoding as UTF-8`);
		charset = 'utf8';
	}
	body = iconv.decode(body, charset);
	result.response = body;
	result.responseText = body;
}
else {