fetchRawFile retrieves the raw bytes of a file, used for files larger than the 1 MB inline content limit of the Contents API.
(httpClient *http.Client, repo ghrepo.Interface, filePath, ref string)
| 171 | // fetchRawFile retrieves the raw bytes of a file, used for files larger than the |
| 172 | // 1 MB inline content limit of the Contents API. |
| 173 | func fetchRawFile(httpClient *http.Client, repo ghrepo.Interface, filePath, ref string) ([]byte, error) { |
| 174 | apiPath := contentsAPIPath(repo, filePath, ref) |
| 175 | |
| 176 | req, err := http.NewRequest("GET", apiPath, nil) |
| 177 | if err != nil { |
| 178 | return nil, err |
| 179 | } |
| 180 | req.Header.Set("Accept", "application/vnd.github.raw") |
| 181 | |
| 182 | resp, err := httpClient.Do(req) |
| 183 | if err != nil { |
| 184 | return nil, err |
| 185 | } |
| 186 | defer resp.Body.Close() |
| 187 | |
| 188 | if resp.StatusCode > 299 { |
| 189 | return nil, api.HandleHTTPError(resp) |
| 190 | } |
| 191 | |
| 192 | return io.ReadAll(resp.Body) |
| 193 | } |
| 194 | |
| 195 | // contentsAPIPath builds the absolute Contents API URL for a path and optional ref. |
| 196 | func contentsAPIPath(repo ghrepo.Interface, filePath, ref string) string { |
no test coverage detected