MCPcopy Index your code
hub / github.com/sqlc-dev/sqlc / downloadFile

Function downloadFile

cmd/sqlc-test-setup/main.go:268–287  ·  view source on GitHub ↗

downloadFile downloads a URL to a local file path.

(filepath string, url string)

Source from the content-addressed store, hash-verified

266
267// downloadFile downloads a URL to a local file path.
268func downloadFile(filepath string, url string) error {
269 resp, err := http.Get(url)
270 if err != nil {
271 return err
272 }
273 defer resp.Body.Close()
274
275 if resp.StatusCode != http.StatusOK {
276 return fmt.Errorf("HTTP %d: %s", resp.StatusCode, resp.Status)
277 }
278
279 out, err := os.Create(filepath)
280 if err != nil {
281 return err
282 }
283 defer out.Close()
284
285 _, err = io.Copy(out, resp.Body)
286 return err
287}
288
289// sha256File computes the SHA256 hash of a file and returns the hex string.
290func sha256File(path string) (string, error) {

Callers 1

installPostgreSQLFunction · 0.85

Calls 2

CloseMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected