MCPcopy Create free account
hub / github.com/SamNet-dev/snix / downloadWithProgress

Function downloadWithProgress

cmd/snix/update.go:165–185  ·  view source on GitHub ↗

downloadWithProgress fetches url into path, streaming to disk to avoid loading the full archive in memory.

(out io.Writer, url, path string)

Source from the content-addressed store, hash-verified

163// downloadWithProgress fetches url into path, streaming to disk to avoid
164// loading the full archive in memory.
165func 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.
188func verifySHA(out io.Writer, path, shaURL string) error {

Callers 1

newUpdateCmdFunction · 0.85

Calls 2

GetMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected