Download goalert/devtools/gettool/fetchfile.go from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 771 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/goalert/devtools/gettool/fetchfile.go
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@f5071caa249115f3b590492f1c8eb471e02aae4b/goalert/devtools/gettool/fetchfile.go
-
curl -L -o fetchfile.go https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/goalert/devtools/gettool/fetchfile.go
771 Bytes
| package main | |
| import ( | |
| "fmt" | |
| "io" | |
| "net/http" | |
| "os" | |
| ) | |
| // fetchFile will download and open a file with the contents of `url`. | |
| func fetchFile(url string) (*os.File, int64, error) { | |
| resp, err := http.Get(url) | |
| if err != nil { | |
| return nil, 0, fmt.Errorf("fetch: %w", err) | |
| } | |
| defer resp.Body.Close() | |
| if resp.StatusCode != 200 { | |
| return nil, 0, fmt.Errorf("non-200 response: %s", resp.Status) | |
| } | |
| fd, err := os.CreateTemp("", "*.zip") | |
| if err != nil { | |
| return nil, 0, fmt.Errorf("create temp file: %w", err) | |
| } | |
| n, err := io.Copy(fd, resp.Body) | |
| if err != nil { | |
| fd.Close() | |
| return nil, 0, fmt.Errorf("download file '%s': %w", url, err) | |
| } | |
| _, err = fd.Seek(0, 0) | |
| if err != nil { | |
| fd.Close() | |
| return nil, 0, fmt.Errorf("seek: %w", err) | |
| } | |
| return fd, n, nil | |
| } | |