-
Notifications
You must be signed in to change notification settings - Fork 0
/
blob.go
46 lines (41 loc) · 817 Bytes
/
blob.go
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
45
46
package git
import "io"
type Blob struct {
*TreeEntry
}
func (b *Blob) Data() (io.ReadCloser, error) {
_, _, dataRc, err := b.ptree.repo.getRawObject(b.Id, false)
if err != nil {
return nil, err
}
return dataRc, nil
}
/*
func (b *Blob) Save(w io.Writer, compress bool) (string, error) {
var data []byte
buf := bytes.NewBuffer(data)
header := fmt.Sprintf("blob %d\\0", len(b.data))
_, err := buf.Write([]byte(header))
if err != nil {
return "", err
}
_, err = buf.Write(b.data)
if err != nil {
return "", err
}
if compress {
var b bytes.Buffer
c := zlib.NewWriter(&b)
_, err = io.Copy(c, buf)
if err != nil {
return "", err
}
_, err = io.Copy(w, &b)
} else {
_, err = io.Copy(w, buf)
}
if err != nil {
return "", err
}
return fmt.Sprintf("%x", sha.Sum(data)), nil
}*/