MCPcopy Create free account
hub / github.com/cli/cli / fetchRawFile

Function fetchRawFile

pkg/cmd/repo/read-file/http.go:176–199  ·  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

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

Callers 1

loadContentFunction · 0.85

Calls 6

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

Tested by

no test coverage detected