Node.js 在NodeJS中复制ArrayBuffers而不损坏时遇到问题

Node.js 在NodeJS中复制ArrayBuffers而不损坏时遇到问题,node.js,copy,arraybuffer,Node.js,Copy,Arraybuffer,我在NodeJS中运行了一些Javascript,试图获取一些来自UDP端口本地端口的数据,并将其收集到更大的块中,然后作为这个块发送 排在第一位 var first_buf = new Uint8Array(1024*1024); 后来 var newbox = get_box(view, last_offset, first_len); if (newbox['type']=='abcd') { buf = view.slice(0, last_offset+newbox['len

我在NodeJS中运行了一些Javascript,试图获取一些来自UDP端口本地端口的数据,并将其收集到更大的块中,然后作为这个块发送

排在第一位

var first_buf = new Uint8Array(1024*1024);
后来

var newbox = get_box(view, last_offset, first_len);
if (newbox['type']=='abcd') {
    buf = view.slice(0, last_offset+newbox['length']);
    this_block = Array.prototype.slice.call(buf);
    buf = view.slice(last_offset+newbox['length'], first_len);
    // adjust first len to account for rest of data
    first_len = first_len - last_offset - newbox['length'];
    // and copy that data into the start of first_buf
    first_buf.set(buf);
    last_offset = 0;
}
else {
    this_block = [];
    buf = view.slice(0, first_len);
    // now copy this into the start of first_buf.
    first_buf.set(buf);
    // first_len is already set correctly, so don't need to adjust

    last_offset += newbox['length'];
}

因此,在本文结束时,我应该将这个_块设置为空数组或要发送的正确arraybuffer。在一段时间内,它可以将数据复制到此块,并将任何备用数据复制到第一个块的开头。经过几次迭代后,块拷贝first_buf.set会破坏数据,我得到垃圾。我想是这个.集造成的,但我看不出是怎么回事。感激地收到任何线索。

好的,我认为问题不在这里。进一步的分析表明,进来的数据偶尔会丢失一大块