概述BYOBReader 允许复用调用方缓冲区,降低分配开销。本文提供最小读取与处理示例。能力检测与 BYOB 读取const supportsRS = typeof ReadableStream === 'function';

async function readBinary(stream, size = 64 * 1024) {

if (!supportsRS) throw new Error('streams unsupported');

const reader = stream.getReader({ mode: 'byob' });

const buf = new Uint8Array(size);

const chunks = [];

while (true) {

const { value, done } = await reader.read(buf);

if (done) break;

chunks.push(value.slice());

}

return chunks;

}

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部