MCPcopy Create free account
hub / github.com/dolthub/doltgresql / DownloadFile

Function DownloadFile

testing/dumps/scraper/main.go:185–204  ·  view source on GitHub ↗

DownloadFile downloads the given SQL file to the destination.

(ctx context.Context, hc *http.Client, item Item, rawURL string, dest string)

Source from the content-addressed store, hash-verified

183
184// DownloadFile downloads the given SQL file to the destination.
185func DownloadFile(ctx context.Context, hc *http.Client, item Item, rawURL string, dest string) error {
186 req, _ := http.NewRequestWithContext(ctx, "GET", rawURL, nil)
187 req.Header.Set("User-Agent", "gh-pg-dump-finder/1.0")
188 resp, err := hc.Do(req)
189 if err != nil {
190 return err
191 }
192 defer resp.Body.Close()
193 if resp.StatusCode != 200 {
194 return fmt.Errorf("download HTTP %d", resp.StatusCode)
195 }
196 out, err := os.Create(dest)
197 if err != nil {
198 return err
199 }
200 defer out.Close()
201 _, _ = io.WriteString(out, fmt.Sprintf("-- Downloaded from: %s\n", item.HtmlURL))
202 _, err = io.Copy(out, resp.Body)
203 return err
204}
205
206// SetHeaders sets the appropriate headers for a request.
207func SetHeaders(req *http.Request, token string) {

Callers 1

mainFunction · 0.85

Calls 5

WriteStringMethod · 0.80
CloseMethod · 0.65
ErrorfMethod · 0.65
CopyMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected