`title: ReadableStream BYOBReader 高效二进制处理``categories: Web 开发/前端/数据管理``keywords: ReadableStreamBYOBReader,BYOB,二进制,性能,OPFS``description: 使用 BYOBReader 在读取二进制数据时复用缓冲区,降低分配与拷贝开销,提升到 OPFS 持久化的性能。`示例async function readWithBYOB(stream) {
const reader = stream.getReader({ mode: 'byob' });
let buf = new Uint8Array(1024 * 1024);
while (true) {
const { done, value } = await reader.read(buf);
if (done) break;
// value 是视图,写入 OPFS 或处理
}
}

发表评论 取消回复