-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblob.go
More file actions
44 lines (37 loc) · 965 Bytes
/
blob.go
File metadata and controls
44 lines (37 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package git
import (
"bytes"
"io"
"io/ioutil"
)
// Blob represents a Git object.
type Blob struct {
repo *Repository
*TreeEntry
}
// Data gets content of blob all at once and wrap it as io.Reader.
// This can be very slow and memory consuming for huge content.
func (b *Blob) Data() (io.Reader, error) {
_, body, err := b.repo.repo.OpenObject(sha2oidp(b.ID))
if err != nil {
return nil, err
}
// FIXME: we can implement something like EOFCloser who autoclose its reader
// after it have been fully read. So we can avoid the buffering
// or we can change the API and return ReadCloser and force the caller to
// close object.
buf, err := ioutil.ReadAll(body)
body.Close()
if err != nil {
return nil, err
}
return bytes.NewBuffer(buf), nil
}
func (b *Blob) DataPipeline(stdout, stderr io.Writer) error {
_, body, err := b.repo.repo.OpenObject(sha2oidp(b.ID))
if err != nil {
return err
}
_, err = io.Copy(stdout, body)
return err
}