MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / fetchWithProgress

Function fetchWithProgress

website/src/pages/Explore.tsx:142–178  ·  view source on GitHub ↗
(
  url: string,
  onProgress: (loaded: number, total: number) => void
)

Source from the content-addressed store, hash-verified

140// FETCH WITH PROGRESS TRACKING
141// ============================================================================
142const fetchWithProgress = async (
143 url: string,
144 onProgress: (loaded: number, total: number) => void
145): Promise<Response> => {
146 const response = await fetch(url);
147 if (!response.ok || !response.body) return response;
148
149 const contentLength = response.headers.get("content-length");
150 const total = contentLength ? parseInt(contentLength, 10) : 0;
151
152 let loaded = 0;
153 const reader = response.body.getReader();
154 const stream = new ReadableStream({
155 async start(controller) {
156 try {
157 while (true) {
158 const { done, value } = await reader.read();
159 if (done) {
160 controller.close();
161 break;
162 }
163 loaded += value.byteLength;
164 onProgress(loaded, total);
165 controller.enqueue(value);
166 }
167 } catch (err) {
168 controller.error(err);
169 }
170 }
171 });
172
173 return new Response(stream, {
174 headers: response.headers,
175 status: response.status,
176 statusText: response.statusText
177 });
178};
179
180const Explore = () => {
181 const [searchParams] = useSearchParams();

Callers 2

fetchWithFallbackProxiesFunction · 0.85
fetchRepositoryFilesFunction · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected