【问题标题】:I have trouble copying ArrayBuffers without corruption in NodeJS我无法在 NodeJS 中复制 ArrayBuffers 而不会损坏
【发布时间】:2020-04-08 19:11:58
【问题描述】:

我在 NodeJS 中运行了一些 Javascript,试图从 UDP 端口(本地端口)获取一些数据,并在将其作为 this_block 发送之前将其收集成更大的块。

在文件顶部

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'];
}

因此,到此结束时,我应该将 this_block 设置为空数组或要发送的正确数组缓冲区。它工作了一段时间,将数据复制到 this_block,并将任何备用复制到 first_buf 的开头。然后经过几次迭代,块副本(first_buf.set)破坏了数据,我得到了垃圾。我认为是 .set 导致它,但我不知道如何。任何线索都感激不尽。

【问题讨论】:

    标签: node.js copy arraybuffer


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-08
      • 2012-10-24
      • 2014-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      相关资源
      最近更新 更多