deno run -A cube.js
// mix strings and buffersDeno.serve(request => new Response(ReadableStream.from(preprocess(request))))let encoder = new TextEncoder()async function * preprocess(request){ for await (let chunk of makeStream(request)) { if (typeof chunk === "string") chunk = encoder.encode(chunk) yield chunk }}async function * makeStream(request){ yield "Hello, " yield encoder.encode("world!")}
// only buffersDeno.serve(request => new Response(ReadableStream.from(makeStream(request))))let encoder = new TextEncoder()async function * makeStream(request){ yield encoder.encode("Hello, ") yield encoder.encode("world!")}
// only stringsDeno.serve(request => new Response(ReadableStream.from(makeStream(request)).pipeThrough(new TextEncoderStream())))async function * makeStream(request){ yield "Hello, " yield "world!"}