-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
Current implementation of Git.GetBlob()
API only supports the JSON media type. This can be inconvenient for vey large git blobs since they are stored completely in memory in the corresponding github.Blob
struct.
The Github GET /repos/:owner/:repo/git/blobs/:sha
API also allows for blobs to be fetched in raw rather than json format using the application/vnd.github.VERSION.raw
media type. This gets around the above limitation for very large blobs.
You can abuse the current API like below but it would be nice to have this feature built into the API.
func DownloadFromGithub(accessToken, owner, repo, sha, toFileName string) error{
//create github client
httpClient := oauth2.NewClient(context.Background(), oauth2.StaticTokenSource(&oauth2.Token{
AccessToken: accessToken,
}))
ghClient := github.NewClient(httpClient)
out, err := os.Create(toFileName)
if err != nil {
return err
}
defer out.Close()
//download the git blob as raw data
u := fmt.Sprintf("repos/%v/%v/git/blobs/%v", owner, repo, sha)
req, err := ghClient.NewRequest("GET", u, nil)
if err != nil{
return err
}
req.Header.Del("Accept")
req.Header.Set("Accept", "application/vnd.github.VERSION.raw")
req.Header.Del("Content-Type")
_, err = ghClient.Do(context.Background(), req, out)
if err != nil{
return err
}
return nil
}
Maybe provide something like this?
func (s *GitService) GetRawBlob(ctx context.Context, owner string, repo string, sha string, to io.Writer) (*Response, error)
Metadata
Metadata
Assignees
Labels
No labels