javascript - Reading a Windows-1252 file in Node JS - Stack Overflow

I'm using node to read a text document using readFile and within that document is a character�Thi

I'm using node to read a text document using readFile and within that document is a character

This is a windows-1252 character but it is being converted in javascript to utf-8 automatically. The correct character should actually display as Å.

Is there a way I can convert this character from utf-8 to windows-1252 to render the correct character?

The file is being read using nodes readFile method and is being read as utf-8, due to the lack of support for the necessary encoding.

fs.readFile(`${logDirectory}myText.txt`,"utf-8", (err, text) => { ... } 

I've tried a few options such as iconv-lite and legacy-decode but neither seem to return the correct result.

Any guidance appreciated.

I'm using node to read a text document using readFile and within that document is a character

This is a windows-1252 character but it is being converted in javascript to utf-8 automatically. The correct character should actually display as Å.

Is there a way I can convert this character from utf-8 to windows-1252 to render the correct character?

The file is being read using nodes readFile method and is being read as utf-8, due to the lack of support for the necessary encoding.

fs.readFile(`${logDirectory}myText.txt`,"utf-8", (err, text) => { ... } 

I've tried a few options such as iconv-lite and legacy-decode but neither seem to return the correct result.

Any guidance appreciated.

Share Improve this question asked Jun 24, 2020 at 14:52 Stephanie ParkerStephanie Parker 4011 gold badge8 silver badges18 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

You can try reading the file with the latin1-encoding as Windows-1252 is based on that:

fs.readFile(`${logDirectory}myText.txt`,'latin1', (err, text) => { ... } 

Also note that in NodeJS the utf-8 encoding is called utf8 instead of utf-8 as described here.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742336993a4424847.html

相关推荐

  • javascript - Reading a Windows-1252 file in Node JS - Stack Overflow

    I'm using node to read a text document using readFile and within that document is a character�Thi

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信