MCPcopy
hub / github.com/resend/react-email / readStream

Function readStream

packages/render/src/shared/read-stream.browser.ts:5–34  ·  view source on GitHub ↗
(stream: ReactDOMServerReadableStream)

Source from the content-addressed store, hash-verified

3const decoder = new TextDecoder('utf-8');
4
5export const readStream = async (stream: ReactDOMServerReadableStream) => {
6 const chunks: Uint8Array[] = [];
7
8 const writableStream = new WritableStream({
9 write(chunk: Uint8Array) {
10 chunks.push(chunk);
11 },
12 abort(reason) {
13 throw new Error('Stream aborted', {
14 cause: {
15 reason,
16 },
17 });
18 },
19 });
20 await stream.pipeTo(writableStream);
21
22 let length = 0;
23 chunks.forEach((item) => {
24 length += item.length;
25 });
26 const mergedChunks = new Uint8Array(length);
27 let offset = 0;
28 chunks.forEach((item) => {
29 mergedChunks.set(item, offset);
30 offset += item.length;
31 });
32
33 return decoder.decode(mergedChunks);
34};

Callers 2

renderFunction · 0.90
renderFunction · 0.90

Calls 2

pipeToMethod · 0.80
forEachMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…