Because js has only one string type. This type is UCS-2/UTF-16. Only Blob or Buffer can truly save UTF-8 encoded data. Therefore, the GB2312 data you read through a web crawler should be directly converted into js internal strings, and then specify utf-8 encoding when saving using the fs API. In this way, the corresponding module is converted when saving. If you want to convert it yourself, the result can only be placed in the Buffer and then written to the file.
Are you talking about unicode character code or utf-8 character code.
If it is a unicode character code, it is similar to:
Just save it like this.
But if it is
Such a character code, then you should convert it to Chinese characters and store it.
For specific coding issues, you can check out this link:
https://www.zhihu.com/questio...
Because js has only one string type. This type is UCS-2/UTF-16. Only Blob or Buffer can truly save UTF-8 encoded data. Therefore, the GB2312 data you read through a web crawler should be directly converted into js internal strings, and then specify utf-8 encoding when saving using the fs API. In this way, the corresponding module is converted when saving.
If you want to convert it yourself, the result can only be placed in the Buffer and then written to the file.