<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          a2uNodeJS 編碼處理模塊

          聯(lián)合創(chuàng)作 · 2023-09-23 16:59

          由于在NodeJs平臺上的缺乏對GBK編碼的處理,對于國人來說比較郁悶,故而出現(xiàn)了a2u、iconv-lite等這樣的GBK編碼處理的模塊。

          a2u 固然沒有 iconv-lite 強(qiáng)大,不過如果你僅需要處理 GB K編碼的話,a2u是比iconv-lite更佳的選擇,只因?yàn)槠渌俣雀臁⑿阅芨谩?/p>

          用法

          解碼 API

          var fs = require('fs');
          var buf = fs.readFileSync('demo.txt'); //txt's encoding is ANSI, the content is "I(我) love(愛) you(你)."
          var a2u = require('a2u');
          var str, newBuf;
          // Convert from an encoded buffer to js string.
          str = a2u.decode(buf);
          console.log(str);//I(我) love(愛) you(你).
          // If you want convert to buffer with ucs2 encoding, the second arg for method(decode) will be true.
          newBuf = a2u.decode(buf, true);
          console.log('ANSI buffer : ', buf);
          console.log('ucs2 buffer : ', newBuf);
          console.log(newBuf.toString('ucs2'));//I(我) love(愛) you(你).

          編碼 API

          var fs = require('fs');
          var a2u = require('a2u');
          var str = "I(我) love(愛) you(你).";
          var buf;
          // If string
          buf = a2u.encode(str);
          console.log('ANSI buffer : ', buf);
          // If buffer
          buf = a2u.encode( new Buffer(str, 'ucs2') );
          console.log('ANSI buffer : ', buf);
          // Write to file
          fs.writeFileSync('ansi.txt', buf);


          瀏覽 19
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  精品国产一区二区三区久久久狼,91精品一 | 亚洲人妻精品导航 | 操操操操操操操操操操操操操逼 | 大香蕉伊人免费在线观看 | 日韩www在线 |