小编idz*_*sky的帖子

在NodeJS中复制Buffer的问题

我正在尝试创建附加缓冲区的方法.

这是代码,它带来了非常奇怪的结果:

   var offset = 0
   var a = new Buffer(0)
   var b = new Buffer('test')

   offset = a.length
   a.length += b.length
   a.copy(b, offset)
   console.log(a.toString())
   // everything works normaly
   // returns: test

   b = new Buffer('hello')
   offset = a.length
   a.length += b.length
   a.copy(b, offset)
   console.log(a.toString())
   // code the same
   // but returns: test<Buff
   // nor: testhello

   // at the third time code doesn't works and raise error: targetStart out of bounds
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

javascript buffer node.js

1
推荐指数
1
解决办法
3396
查看次数

标签 统计

buffer ×1

javascript ×1

node.js ×1