MCPcopy Create free account
hub / github.com/ScattrdBlade/bigFileUpload / progressStream

Function progressStream

native.ts:26–50  ·  view source on GitHub ↗
(parts: Uint8Array[])

Source from the content-addressed store, hash-verified

24const UPLOAD_CHUNK_SIZE = 262144; // 256 KB
25
26function progressStream(parts: Uint8Array[]): ReadableStream<Uint8Array> {
27 const total = parts.reduce((sum, part) => sum + part.length, 0);
28 uploadProgress = { loaded: 0, total };
29 let index = 0;
30 let offset = 0;
31 let loaded = 0;
32 return new ReadableStream({
33 pull(controller) {
34 while (index < parts.length && offset >= parts[index].length) {
35 index++;
36 offset = 0;
37 }
38 if (index >= parts.length) {
39 controller.close();
40 return;
41 }
42 const part = parts[index];
43 const end = Math.min(offset + UPLOAD_CHUNK_SIZE, part.length);
44 controller.enqueue(part.subarray(offset, end));
45 loaded += end - offset;
46 offset = end;
47 uploadProgress = { loaded, total };
48 }
49 });
50}
51
52function streamFetch(url: string, method: string, headers: Record<string, string>, parts: Uint8Array[], contentType?: string): Promise<Response> {
53 const total = parts.reduce((sum, part) => sum + part.length, 0);

Callers 1

streamFetchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected