使用 Iconv 在 nodejs 中转换编码

transform coding in nodejs with Iconv

我正在尝试对文本进行编码转换,以获取原始文本。但它只是 returns 来自我创建的变量的正确文本,而不是另一个函数的变量。 一个专业,当我尝试转换另一个文本(Hakaba Kitarō)时出现错误: (node:5436) UnhandledPromiseRejectionWarning: Error: Illegal character sequence.

function iso_to_utf8 (text) {
    console.log(`text orginal: ${text}`); //return text orginal: "Queen\u00c2\u0092s Blade OVA 2011"
    body = new Buffer.from(text, "utf8");
    conv = new Iconv("utf8//TRANSLIT//IGNORE", "ISO-8859-1");
    body = conv.convert(body).toString();
    console.log(body); //return Queen\u00c2\u0092s Blade OVA 2011
    body = new Buffer.from("Queen\u00c2\u0092s Blade OVA 2011", "utf8");
    conv = new Iconv("utf8//TRANSLIT//IGNORE", "ISO-8859-1");
    body = conv.convert(body).toString();
    console.log(body); //return Queens Blade OVA 2011

    return body;
}

这是关于 \u00c2\u0092 字符序列?这是转换为UTF-8时的字节序列\xc3\x82\xc2\x92。

//TRANSLIT 正确地将其作为 ISO-8859-1 字节序列复制到输出缓冲区 \xc2\x92,然后 .toString() 将其解释为 UTF-8 并转换为 U+0092,一个控件您的终端可能会或可能不会显示的字符。

(顺便说一下,U+007F-U+009F 范围内的所有字符都是控制字符。)

这是所有预期的行为并且按预期工作,所以我将继续并关闭它。 来自 bnoordhuis