ReadableStreamBYOBReader.read忽略Chrome上的偏移量

lfapxunr  于 11个月前  发布在  Go
关注(0)|答案(1)|浏览(142)

我尝试使用ReadableStreamBYOBReader读取一个数据拷贝量最小的文件,但似乎reader没有在Chrome中以正确的偏移量进行阅读和写入。
在下面的例子中,我只是简单地调用ReadableStreamBYOBReader.read两次,看看缓冲区发生了什么。
该示例派生自developer.mozilla.org上的示例(按原样复制它们的示例也会在调试器中产生相同的行为)

<input type="file" onchange="upload(event)" />
<script>
    async function upload(event) {
        const reader = event.target.files[0].stream().getReader({ mode: 'byob' });

        let buffer = new ArrayBuffer(16777216);
        let offset = 0;

        const read1 = await reader.read(new Uint8Array(buffer, offset, 8388608));

        console.log('1', read1.value, new Uint8Array(read1.value.buffer));

        buffer = read1.value.buffer;
        offset += read1.value.byteLength;

        const read2 = await reader.read(new Uint8Array(buffer, offset, 8388608));

        console.log('2', read2.value, new Uint8Array(read2.value.buffer));
    }
</script>

字符串
我希望readX.valueArrayBufferView,对应于reader.read刚刚读取的内容(ArrayBufferView是开始时分配的16 MB缓冲区的偏移视图)。
我希望new Uint8Array(readX.value.buffer)在这两种情况下都是满的缓冲区,在第一个console.log中只填充一个reader.read的数据,在第二个中只填充两个reader.read的数据。
这正是我在Firefox中看到的:
但不是在Chrome中:
在我用于测试的文件中:

  • [ 0, 0, 0, 32, 102]是文件的开头
  • [100, 63, 56, 65, 149]的偏移量为65536
  • [ 28, 192, 91, 173, 156]的偏移量为131072

正如预期的那样,在Firefox中,两个readX.value是刚刚读取的块,一个紧挨着另一个;而new Uint8Array是完整的缓冲区,两个块紧挨着显示。
但是在Chrome中,在第二次调用中,read2.value以某种方式包含了偏移量为131072的内容(而之前它只读取了64 k的一个块);而且它似乎在缓冲区的开头写入了预期的内容(从偏移量65536开始),忽略了第二次read调用中作为参数给出的偏移量。
复检注意事项:Chrome是恼人的,因为它从来没有读取相同大小的块,有时一次读取几MB,因此大8 MB缓冲区的阅读(这种行为不会重现时,阅读到一个小(几KB)ArrayBufferView)

kq0g1dla

kq0g1dla1#

要报告Chrome错误,请使用crbug.com/new(和/或搜索crbug.com上的现有问题)。
这个特殊的问题听起来像crbug.com/1492093,两周前已经修复。

相关问题