MCPcopy Create free account
hub / github.com/TanStack/router / createStreamConsumer

Function createStreamConsumer

e2e/solid-start/basic/src/raw-stream-fns.ts:371–394  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

369// but after SSR deserialization it becomes ReadableStream<Uint8Array>.
370// We accept both types to handle the TypeScript mismatch.
371export function createStreamConsumer() {
372 const decoder = new TextDecoder()
373
374 return async function consumeStream(
375 stream: ReadableStream<Uint8Array> | RawStream,
376 ): Promise<string> {
377 // Handle both RawStream (from type system) and ReadableStream (runtime)
378 const actualStream =
379 stream instanceof RawStream
380 ? stream.stream
381 : (stream as ReadableStream<Uint8Array>)
382 const reader = actualStream.getReader()
383 const chunks: Array<string> = []
384
385 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
386 while (true) {
387 const { done, value } = await reader.read()
388 if (done) break
389 chunks.push(decoder.decode(value, { stream: true }))
390 }
391
392 return chunks.join('')
393 }
394}
395
396export async function consumeBinaryStream(
397 stream: ReadableStream<Uint8Array> | RawStream,

Callers 4

SSRMixedTestFunction · 0.90
SSRSingleTestFunction · 0.90
ClientCallTestsFunction · 0.90
SSRMultipleTestFunction · 0.90

Calls 1

getReaderMethod · 0.65

Tested by

no test coverage detected