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