How to use the iconv-lite.decode function in iconv-lite

To help you get started, we’ve selected a few iconv-lite examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AntSwordProject / antSword / source / modules / filemanager / index.js View on Github external
if (ret === '1') {
            toastr.success(LANG['editor']['success'](path), LANG_T['success']);
            // 刷新目录(显示更改时间、大小等)
            self.files.refreshPath();
          } else {
            toastr.error(LANG['editor']['error'](path, ret === '0' ? '' : '<br>' + ret), LANG_T['error']);
          }
        }).catch((err) =&gt; {

        });
      } else if (id.startsWith('mode_')) {
        let mode = id.split('_')[1];
        editor.session.setMode(`ace/mode/${mode}`);
      } else if (id.startsWith('encode_')) {
        let encode = id.split('_')[1];
        editor.session.setValue(iconv.decode(Buffer.from(codes), encode).toString());
      } else if (id === 'refresh') {
        // 获取文件代码
        win.progressOn()
        this.core.request(
          this.core.filemanager.read_file({
            path: path
          })
        ).then((res) =&gt; {
          win.progressOff();
          name = path.substr(path.lastIndexOf('/') + 1);
          if (openfileintab == false) {
            win.setText(LANG['editor']['title'](antSword.noxss(path)));
          } else {
            win.setText(`<i class="fa fa-file-o"></i> ${antSword.noxss(name)}`);
          }
          ext = name.substr(name.lastIndexOf('.') + 1);
github web-driverify / web-driverify / src / proxy / routes / external.js View on Github external
  .then(buffer => iconv.decode(buffer, cs))
  // .tap(html => debug('decoded html:', string(html).summary(64)))
github mooyoul / telegrambot-readerman / lib / fetch.js View on Github external
xmlEncoding = getEncodingFromXML(body),
        contentEncoding = xmlEncoding || httpEncoding;


      if (!httpEncoding && !xmlEncoding) {
        log('no encoding information. setting contentEncoding to utf8... (url: %s)', url);
        contentEncoding = 'utf8';
      }
      if ((httpEncoding && xmlEncoding) && (httpEncoding !== xmlEncoding)) {
        log('encoding is different between http header and xml header. (http: %s, xml: %s, url: %s)', httpEncoding, xmlEncoding, url);
      }


      if (contentEncoding.substr(0, 3) !== 'utf') { // content should be decoded
        log('encoding %s detected. decoding... (url: %s)', contentEncoding, url);
        body = iconv.decode(bufBody, contentEncoding);
      }

      feedparser.end(body);
    });
  });
github swsmn / node-cli / __test__ / 1.js View on Github external
(err, stdout, stderr) => {
    console.log(
      err,
      iconv.decode(stdout, 'cp936'),
      iconv.decode(stderr, 'cp936')
    )
  }
)
github ljharb / qs / test / parse.js View on Github external
decoder: function (str) {
                var reg = /%([0-9A-F]{2})/ig;
                var result = [];
                var parts = reg.exec(str);
                while (parts) {
                    result.push(parseInt(parts[1], 16));
                    parts = reg.exec(str);
                }
                return String(iconv.decode(SaferBuffer.from(result), 'shift_jis'));
            }
        }), { 県: '大阪府' });
github DIYgod / RSSHub / lib / routes / oilprice / index.js View on Github external
module.exports = async (ctx) =&gt; {
    const { area } = ctx.params;
    const link = 'http://oil.usd-cny.com/';
    const response = await got({
        method: 'get',
        url: link,
        responseType: 'buffer',
    });
    const $ = cheerio.load(iconv.decode(response.data, 'gb2312'));
    const $list = $('.content')
        .eq(0)
        .find('table tbody tr');
    const resultItem = [];
    let areaName = '';
    const updateTime = $('.time')
        .text()
        .split(':')[1];
    const labelList = $list
        .eq(1)
        .find('td')
        .slice(1)
        .map((index, item) =&gt; $(item).text())
        .get();

    for (let i = 2; i &lt; $list.length; i++) {
github shanelau / rssSpider / lib / rss.js View on Github external
}).pipe(es.through(function(data) {

      //get charset from 
      //then convert gb2312,gbk,big5 etc to utf-8

      var result = data.toString('utf-8');

      var meta = result.match(/&lt;\?(.*?)\?&gt;/g);
      if (meta !== null) {
        meta = meta[0].toString().match(/encoding="(.*?)"\?&gt;/g);
        encoding = meta.toString().split('"')[1];
      }

      //iconv-lite , which can support windows
      result = iconv.decode(data, encoding);
      this.emit('data', result);
    })).pipe(feedparser);
github ooooevan / Vmail / src / renderer / common / javascript / parseEmail.js View on Github external
const buff = Buffer.from(thridContentText, transferEncoding)
                plainText = iconv.decode(buff, charset || 'utf-8')
              } else {
                try {
                  plainText = Buffer.from(thridContentText, transferEncoding).toString()
                } catch (e) {
                  plainText = thridContentText
                }
              }
              result.bodyText = plainText
            } else if (contentType.match(htmlTypeReg)) {
              let htmlText = ''
              if (transferEncoding === 'base64') {
                const charset = subText.match(secondChartsetReg) && subText.match(secondChartsetReg)[1].replace(/"/g, '')
                const htmlBuffer = Buffer.from(thridContentText, 'base64')
                htmlText = iconv.decode(htmlBuffer, charset || 'utf-8')
              } else if (transferEncoding === 'quoted-printable') {
                const charset = subText.match(secondChartsetReg) && subText.match(secondChartsetReg)[1].replace(/"/g, '')
                let quotedHtml
                if (charset && !charset.match(/utf/i)) {
                  quotedHtml = iconv.decode(quotedPrintable.decode(thridContentText), charset)
                } else {
                  quotedHtml = utf8.decode(quotedPrintable.decode(thridContentText))
                }
                htmlText = quotedHtml
              } else {
                try {
                  htmlText = Buffer.from(thridContentText, transferEncoding).toString()
                } catch (e) {
                  htmlText = thridContentText
                }
              }
github James-Yu / LaTeX-Workshop / src / utils / utils.ts View on Github external
export function convertFilenameEncoding(filePath: string): string | undefined {
    for (const enc of iconvLiteSupportedEncodings) {
        try {
            const fpath = iconv.decode(Buffer.from(filePath, 'binary'), enc)
            if (fs.existsSync(fpath)) {
                return fpath
            }
        } catch (e) {

        }
    }
    return undefined
}
github zengzhan / qqzeng-ip / ip-old / node-js / IPSearch.js View on Github external
function pushString(array, addr){
	if(addr==0){
		array.push('未知');
		return 0;
	}
	var buf = new Buffer(255);
	var stringEnd = addr;
	while(geodat[stringEnd]){
		stringEnd++;
	}
	array.push(iconv.decode(geodat.slice(addr, stringEnd), 'GBK'));
	return stringEnd;
}