downloadWithProgress fetches url into path, streaming to disk to avoid loading the full archive in memory.
(out io.Writer, url, path string)
| 163 | // downloadWithProgress fetches url into path, streaming to disk to avoid |
| 164 | // loading the full archive in memory. |
| 165 | func downloadWithProgress(out io.Writer, url, path string) error { |
| 166 | resp, err := http.Get(url) |
| 167 | if err != nil { |
| 168 | return err |
| 169 | } |
| 170 | defer resp.Body.Close() |
| 171 | if resp.StatusCode != 200 { |
| 172 | return fmt.Errorf("HTTP %d", resp.StatusCode) |
| 173 | } |
| 174 | f, err := os.Create(path) |
| 175 | if err != nil { |
| 176 | return err |
| 177 | } |
| 178 | defer f.Close() |
| 179 | n, err := io.Copy(f, resp.Body) |
| 180 | if err != nil { |
| 181 | return err |
| 182 | } |
| 183 | fmt.Fprintf(out, "downloaded %d bytes\n", n) |
| 184 | return nil |
| 185 | } |
| 186 | |
| 187 | // verifySHA fetches the sibling .sha256 file and compares. |
| 188 | func verifySHA(out io.Writer, path, shaURL string) error { |
no test coverage detected