(url: string, dest: string)
| 26 | } |
| 27 | |
| 28 | async function downloadWithRetry(url: string, dest: string): Promise<void> { |
| 29 | for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) { |
| 30 | try { |
| 31 | const response = await fetch(url); |
| 32 | if (!response.ok) { |
| 33 | throw new Error(`HTTP ${response.status}: ${response.statusText}`); |
| 34 | } |
| 35 | await Bun.write(dest, response); |
| 36 | return; |
| 37 | } catch (error) { |
| 38 | const isLastAttempt = attempt === MAX_RETRIES; |
| 39 | console.error( |
| 40 | `Download attempt ${attempt}/${MAX_RETRIES} failed:`, |
| 41 | error instanceof Error ? error.message : error |
| 42 | ); |
| 43 | if (isLastAttempt) { |
| 44 | throw new Error( |
| 45 | `Failed to download spec after ${MAX_RETRIES} attempts: ${ |
| 46 | error instanceof Error ? error.message : error |
| 47 | }` |
| 48 | ); |
| 49 | } |
| 50 | const backoff = INITIAL_BACKOFF_MS * Math.pow(2, attempt - 1); |
| 51 | console.log(`Retrying in ${backoff}ms...`); |
| 52 | await Bun.sleep(backoff); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | async function unzipToDirectoryAsync( |
| 58 | zipFile: string, |
no outgoing calls
no test coverage detected