NodeJS 编码处理模块 a2u

码农软件 · 软件分类 · Node.js 扩展 · 2019-04-14 22:56:55

软件介绍

由于在NodeJs平台上的缺乏对GBK编码的处理,对于国人来说比较郁闷,故而出现了a2u、iconv-lite等这样的GBK编码处理的模块。

a2u 固然没有 iconv-lite 强大,不过如果你仅需要处理 GB K编码的话,a2u是比iconv-lite更佳的选择,只因为其速度更快、性能更好。

用法

解码 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);


本文地址:https://codercto.com/soft/d/3600.html

设计模式之禅

设计模式之禅

秦小波 / 机械工业出版社 / 2010年3月 / 69.00元

如果说“四人帮”的《设计模式》是设计模式领域的“圣经”,那么之后出版的各种关于设计模式的书都可称之为“圣经”的“注释版”或“圣经的故事”。本书是得道者对“圣经”的“禅悟”,它既不像“圣经”那样因为惜字如金、字字珠玑而深奥、晦涩和难懂,又比“圣经”的“注释版”更深刻和全面、更通俗和生动、更接近开发者遇到的实践场景,更具指导性。本书兼收并蓄、博采众长,也许是设计模式领域里的下一个里程碑之作。 全......一起来看看 《设计模式之禅》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具