/
blob.go
71 lines (54 loc) · 1.29 KB
/
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
61
62
63
64
65
66
67
68
69
70
71
package ipldgit
import (
"encoding/json"
"errors"
cid "github.com/ipfs/fs-repo-migrations/ipfs-10-to-11/_vendor/github.com/ipfs/go-cid"
node "github.com/ipfs/fs-repo-migrations/ipfs-10-to-11/_vendor/github.com/ipfs/go-ipld-format"
)
type Blob struct {
rawData []byte
cid cid.Cid
}
func (b *Blob) Cid() cid.Cid {
return b.cid
}
func (b *Blob) Copy() node.Node {
nb := *b
return &nb
}
func (b *Blob) Links() []*node.Link {
return nil
}
func (b *Blob) Resolve(_ []string) (interface{}, []string, error) {
return nil, nil, errors.New("no such link")
}
func (b *Blob) ResolveLink(_ []string) (*node.Link, []string, error) {
return nil, nil, errors.New("no such link")
}
func (b *Blob) Loggable() map[string]interface{} {
return map[string]interface{}{
"type": "git_blob",
}
}
func (b *Blob) MarshalJSON() ([]byte, error) {
return json.Marshal(b.rawData)
}
func (b *Blob) RawData() []byte {
return []byte(b.rawData)
}
func (b *Blob) Size() (uint64, error) {
return uint64(len(b.rawData)), nil
}
func (b *Blob) Stat() (*node.NodeStat, error) {
return &node.NodeStat{}, nil
}
func (b *Blob) String() string {
return "[git blob]"
}
func (b *Blob) Tree(p string, depth int) []string {
return nil
}
func (b *Blob) GitSha() []byte {
return cidToSha(b.Cid())
}
var _ node.Node = (*Blob)(nil)