What encodings does Buffer.toString() support?

后端 未结 3 1384
心在旅途
心在旅途 2020-12-30 19:05

I\'m writing an app in node.js, and see that I can do things like this:

var buf = new Buffer(\"Hello World!\")
console.log(buf.toString(\"hex\"))
console.log         


        
相关标签:
3条回答
  • 2020-12-30 19:39

    The official node.js documentation for Buffer is the best place to check for something like this. As previously noted, Buffer currently supports these encodings: ascii, utf8, utf16le/ucs2, base64, binary, and hex.

    0 讨论(0)
  • 2020-12-30 19:55

    It support ascii , utf-8 , ucs2, base64, binary

    0 讨论(0)
  • 2020-12-30 19:56

    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.php has the answer. You can use the following types in .toString() on a buffer:

    • ascii
    • utf8
    • utf16le
    • ucs2 (alias of utf16le)
    • base64
    • binary
    • hex
    0 讨论(0)
提交回复
热议问题