我正在尝试创建附加缓冲区的方法.
这是代码,它带来了非常奇怪的结果:
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)
我做错了什么?