admin管理员组文章数量:1426491
I have been working with node's fs.readFileSync()
, passing "utf8"
as the encoding to read input. When the file contains a BOM character in UTF8 (0xEF 0xBF 0xBB) it converts it to the byte sequence 0xFE 0xFF instead, which is the Unicode encoding.
Why does it do this? Why not keep the origin sequence for BOMs in UTF8?
I have been working with node's fs.readFileSync()
, passing "utf8"
as the encoding to read input. When the file contains a BOM character in UTF8 (0xEF 0xBF 0xBB) it converts it to the byte sequence 0xFE 0xFF instead, which is the Unicode encoding.
Why does it do this? Why not keep the origin sequence for BOMs in UTF8?
Share Improve this question edited Jul 20, 2013 at 1:05 mor 2,31318 silver badges28 bronze badges asked Jul 20, 2013 at 0:52 Rick EyreRick Eyre 2,5054 gold badges21 silver badges27 bronze badges 01 Answer
Reset to default 7The BOM is character U+FEFF. 0xEF 0xBB 0xBF is its UTF-8 representation. But by reading with an encoding of utf8, you're decoding UTF-8. At this point it bees meaningless to talk about a "byte sequence"; you have a string of characters, the first of which is U+FEFF.
本文标签: javascriptWhy does Nodejs convert BOM character to 0xFE 0xFFStack Overflow
版权声明:本文标题:javascript - Why does Node.js convert BOM character to 0xFE 0xFF? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745404503a2657190.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论