(url: string, filePath: string)
| 91 | } |
| 92 | |
| 93 | |
| 94 | async function fetchToBuffer(url: string): Promise<Buffer> { |
| 95 | const res = await fetch(url); |
| 96 | if (!res.ok) throw new Error(`GET ${url} failed: ${res.status} ${res.statusText}`); |
| 97 | return Buffer.from(await res.arrayBuffer()); |
| 98 | } |
| 99 | |
| 100 | async function downloadFileIfMissingOrChanged(url: string, filePath: string): Promise<void> { |
| 101 | fs.mkdirSync(path.dirname(filePath), { recursive: true }); |
| 102 | const data = await fetchToBuffer(url); |
| 103 | if (fs.existsSync(filePath)) { |
| 104 | const old = fs.readFileSync(filePath); |
no test coverage detected