Why does console.log(buffer) give me a hexadecimal list?

后端 未结 1 427
醉酒成梦
醉酒成梦 2021-01-01 10:43

Here is my CoffeeScript:

buffer = new Buffer 100
buffer[i] = i for i in [0..99]
console.log buffer

which compiles to

  var          


        
相关标签:
1条回答
  • 2021-01-01 11:22

    Ray nailed it in his comment. See the Buffer documentation; you have to specify an encoding argument (you probably want 'utf8') on a Buffer's toString.

    // coffeescript
    console.log buffer.toString 'utf8'
    // javascript
    console.log(buffer.toString('utf8'));
    
    0 讨论(0)
提交回复
热议问题