MCPcopy Index your code
hub / github.com/cli/cli / fetchRawFile

Function fetchRawFile

pkg/cmd/repo/read-file/http.go:173–193  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
173func 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.
196func contentsAPIPath(repo ghrepo.Interface, filePath, ref string) string {

Callers 1

loadContentFunction · 0.85

Calls 5

HandleHTTPErrorFunction · 0.92
contentsAPIPathFunction · 0.85
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected