MCPcopy Index your code
hub / github.com/rilldata/rill / downloadFile

Function downloadFile

scripts/embed_duckdb_ext/main.go:80–103  ·  view source on GitHub ↗

downloadFile downloads a file from a URL and saves it to a destination path

(url, dest string)

Source from the content-addressed store, hash-verified

78
79// downloadFile downloads a file from a URL and saves it to a destination path
80func downloadFile(url, dest string) error {
81 resp, err := http.Get(url)
82 if err != nil {
83 return fmt.Errorf("failed to perform HTTP GET request: %w", err)
84 }
85 defer resp.Body.Close()
86
87 if resp.StatusCode != http.StatusOK {
88 return fmt.Errorf("unexpected HTTP status: %s", resp.Status)
89 }
90
91 out, err := os.Create(dest)
92 if err != nil {
93 return fmt.Errorf("failed to create file: %w", err)
94 }
95 defer out.Close()
96
97 _, err = io.Copy(out, resp.Body)
98 if err != nil {
99 return fmt.Errorf("failed to copy response body to file: %w", err)
100 }
101
102 return nil
103}

Callers 1

mainFunction · 0.70

Calls 4

CreateMethod · 0.80
GetMethod · 0.65
ErrorfMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected