-
Notifications
You must be signed in to change notification settings - Fork 1
/
blob.go
60 lines (47 loc) · 885 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package git
import (
"bytes"
)
type Blob struct {
repo *Git
name Ptr
data []byte
}
func (g *Git) loadBlob(n *Ptr, data []byte) (*Blob, error) {
return &Blob{
repo: g,
name: *n,
data: data,
}, nil
}
func (b *Blob) Value() string {
return string(b.data)
}
func (b *Blob) Name() *Ptr {
return &b.name
}
func (b *Blob) Type() ObjType {
return ObjBlob
}
func (b *Blob) Payload() ([]byte, error) {
return b.data, nil
}
func (b *Blob) Load() (GitObject, error) {
return b, nil
}
func (b *Blob) Open() *BlobReader {
return &BlobReader{bytes.NewReader(b.data)}
}
type BlobReader struct {
*bytes.Reader
}
func (br *BlobReader) Read(buf []byte) (int, error) {
return br.Reader.Read(buf)
}
func (br *BlobReader) Seek(off int64, whence int) (int64, error) {
return br.Reader.Seek(off, whence)
}
func (br *BlobReader) Close() error {
br.Reader = nil
return nil
}