a2u 解码 API编码 API NodeJS 编码处理模块

程序名称:a2u 解码 API编码 API

授权协议: MIT

操作系统: 跨平台

开发语言: JavaScript

a2u 解码 API编码 API 介绍

由于在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);

a2u 解码 API编码 API 官网

https://www.npmjs.com/package/a2u

相关编程语言

MuPlayer 是一款跨平台、轻量级的音频播放解决方案,...
OS FLV 是一个 开源和可嵌入网页的flv播放器。 这个...
DewPlayer音乐播放器,样式很简单,而且很实用.播放器...
JW FLV MEDIA PLAYER是一个开源的在网页上使用的Fla...
Speakker 是一个基于 Web 浏览器的音乐播放器,只提...
Player Framework 是一个开源的支持 HTML5 的视频播...