MCPcopy Create free account
hub / github.com/cloudflare/computer / drainBytes

Function drainBytes

packages/computer/src/workspace.ts:1196–1219  ·  view source on GitHub ↗
(stream: ReadableStream<Uint8Array>)

Source from the content-addressed store, hash-verified

1194}
1195
1196async function drainBytes(stream: ReadableStream<Uint8Array>): Promise<Uint8Array> {
1197 const reader = stream.getReader();
1198 const parts: Uint8Array[] = [];
1199 let total = 0;
1200 try {
1201 while (true) {
1202 const { value, done } = await reader.read();
1203 if (done) break;
1204 if (!value) continue;
1205 parts.push(value);
1206 total += value.byteLength;
1207 }
1208 } finally {
1209 reader.releaseLock();
1210 }
1211 if (parts.length === 1) return parts[0];
1212 const out = new Uint8Array(total);
1213 let offset = 0;
1214 for (const part of parts) {
1215 out.set(part, offset);
1216 offset += part.byteLength;
1217 }
1218 return out;
1219}
1220
1221function toThinkFileInfo(input: {
1222 path: string;

Callers 1

readFileBytesFunction · 0.85

Calls 4

getReaderMethod · 0.65
readMethod · 0.65
pushMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected