MCPcopy
hub / github.com/coder/mux / readStreamToBuffer

Function readStreamToBuffer

src/node/utils/attachments/readAttachmentFromPath.ts:102–117  ·  view source on GitHub ↗
(stream: ReadableStream<Uint8Array>)

Source from the content-addressed store, hash-verified

100}
101
102async function readStreamToBuffer(stream: ReadableStream<Uint8Array>): Promise<Buffer> {
103 const reader = stream.getReader();
104 const chunks: Buffer[] = [];
105
106 try {
107 while (true) {
108 const { done, value } = await reader.read();
109 if (done) break;
110 chunks.push(Buffer.from(value));
111 }
112 } finally {
113 reader.releaseLock();
114 }
115
116 return Buffer.concat(chunks);
117}
118
119function formatBytesAsMegabytes(bytes: number): string {
120 return `${(bytes / (1024 * 1024)).toFixed(2)}MB`;

Callers 1

readRegularFileBytesFunction · 0.70

Calls 2

pushMethod · 0.65
readMethod · 0.45

Tested by

no test coverage detected