node.js Buffer.toString() 支持哪些编码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34476754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What encodings does Buffer.toString() support?
提问by Grayda
I'm writing an app in node.js, and see that I can do things like this:
我正在 node.js 中编写一个应用程序,并看到我可以做这样的事情:
var buf = new Buffer("Hello World!")
console.log(buf.toString("hex"))
console.log(buf.toString("utf8"))
And I know of 'ascii' as an encoding type (it'll take an ASCII code, such as 112and turn it into a p), but what other types of encoding can I do?
而且我知道“ascii”是一种编码类型(它将采用 ASCII 代码,例如112并将其转换为 a p),但是我可以做哪些其他类型的编码?
回答by mscdex
The official node.js documentation for Bufferis the best place to check for something like this. As previously noted, Buffercurrently supports these encodings: ascii, utf8, utf16le/ucs2, base64, binary, and hex.
官方node.js 文档Buffer是检查此类内容的最佳位置。如前所述,Buffer目前支持这些编码:ascii,utf8,utf16le/ ucs2,base64,binary,和hex。
回答by Grayda
As is always the way, I spent a while Googling but found nothing until after I posted the question:
一如既往,我花了一段时间谷歌搜索,但在我发布问题之前什么也没找到:
http://www.w3resource.com/node.js/nodejs-buffer.phphas the answer. You can use the following types in .toString()on a buffer:
http://www.w3resource.com/node.js/nodejs-buffer.php有答案。您可以在.toString()缓冲区中使用以下类型:
asciiutf8utf16leucs2(alias ofutf16le)base64binaryhex
asciiutf8utf16leucs2(的别名utf16le)base64binaryhex
回答by trquoccuong
It support ascii , utf-8 , ucs2, base64, binary
IT支持 ascii , utf-8 , ucs2, base64, binary

