MCPcopy Index your code
hub / github.com/ColmapView/Colmapview.github.io / readStreamingResponseBlob

Function readStreamingResponseBlob

src/utils/zipDownload.ts:71–98  ·  view source on GitHub ↗
(
  body: ReadableStream<Uint8Array>,
  total: number,
  onProgress: ZipProgressCallback
)

Source from the content-addressed store, hash-verified

69}
70
71async function readStreamingResponseBlob(
72 body: ReadableStream<Uint8Array>,
73 total: number,
74 onProgress: ZipProgressCallback
75): Promise<Blob> {
76 const reader = body.getReader();
77 const chunks: Uint8Array[] = [];
78 let loaded = 0;
79
80 while (true) {
81 const { done, value } = await reader.read();
82 if (done) break;
83
84 chunks.push(new Uint8Array(value));
85 loaded += value.length;
86 onProgress(getDownloadProgress(loaded, total));
87 }
88
89 const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
90 const result = new Uint8Array(totalLength);
91 let offset = 0;
92 for (const chunk of chunks) {
93 result.set(chunk, offset);
94 offset += chunk.length;
95 }
96
97 return new Blob([result]);
98}
99
100function getDownloadProgress(loaded: number, total: number): ZipProgress {
101 if (total > 0) {

Callers 1

downloadZipFunction · 0.85

Calls 1

getDownloadProgressFunction · 0.85

Tested by

no test coverage detected