6
6
package github
7
7
8
8
import (
9
+ "bytes"
9
10
"context"
10
11
"fmt"
11
12
)
@@ -20,7 +21,7 @@ type Blob struct {
20
21
NodeID * string `json:"node_id,omitempty"`
21
22
}
22
23
23
- // GetBlob fetchs a blob from a repo given a SHA.
24
+ // GetBlob fetches a blob from a repo given a SHA.
24
25
//
25
26
// GitHub API docs: https://developer.github.com/v3/git/blobs/#get-a-blob
26
27
func (s * GitService ) GetBlob (ctx context.Context , owner string , repo string , sha string ) (* Blob , * Response , error ) {
@@ -38,6 +39,23 @@ func (s *GitService) GetBlob(ctx context.Context, owner string, repo string, sha
38
39
return blob , resp , err
39
40
}
40
41
42
+ // GetBlobRaw fetches a blob's contents from a repo.
43
+ // Unlike GetBlob, it returns the raw bytes rather than the base64-encoded data.
44
+ //
45
+ // GitHub API docs: https://developer.github.com/v3/git/blobs/#get-a-blob
46
+ func (s * GitService ) GetBlobRaw (ctx context.Context , owner , repo , sha string ) ([]byte , * Response , error ) {
47
+ u := fmt .Sprintf ("repos/%v/%v/git/blobs/%v" , owner , repo , sha )
48
+ req , err := s .client .NewRequest ("GET" , u , nil )
49
+ if err != nil {
50
+ return nil , nil , err
51
+ }
52
+ req .Header .Set ("Accept" , "application/vnd.github.v3.raw" )
53
+
54
+ var buf bytes.Buffer
55
+ resp , err := s .client .Do (ctx , req , & buf )
56
+ return buf .Bytes (), resp , err
57
+ }
58
+
41
59
// CreateBlob creates a blob object.
42
60
//
43
61
// GitHub API docs: https://developer.github.com/v3/git/blobs/#create-a-blob
0 commit comments