概述TransformStream 提供可组合的数据管道能力。本文给出能力检测与端到端处理示例。能力检测与处理管道const supportsTS = typeof TransformStream === 'function'; function toUpperTransform() { return new TransformStream({ transform(chunk, controller) { const s = typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk); controller.enqueue(new TextEncoder().encode(s.toUpperCase())); } }); } async function processText(text) { if (!supportsTS) return text.toUpperCase(); const rs = new Blob([text]).stream(); const out = rs.pipeThrough(toUpperTransform()); return await new Response(out).text(); }

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部