nodejs和js里的gbk与utf8编码转换
nodejs和js里的gbk与utf8编码转换
js 与 nodejs 都有 TextEncoder
TextDecoder
,可以进行编码之间的转换
nodejs 版本需要 >=8.3.0 才支持 util.TextEncoder,util.TextDecoder
gbk 转 utf8
1 | new TextDecoder('gbk').decode(new Uint8Array([ 47, 63, 214, 208, 206, 196, 61, 56, 56 ]).buffer) |
nodejs 建议通过 iconv or iconv-lite第三方库进行编码之间的转换。因为使用原生 TextEncoder需要完整的 ICU Data 具体看这里 util_class_util_textdecoder
utf8 gbk 互转
1 | let iconv = require('iconv-lite'); |
感谢您的阅读,本文由 smallwhite's Blog 版权所有。如若转载,请注明出处:smallwhite's Blog(https://smallwhite.ml/pub/nodejs/nodejs-js-gbk-utf8-encode.html)