@@ -5,67 +5,62 @@ import (
5
5
6
6
cid "github.com/ipfs/go-cid"
7
7
node "github.com/ipfs/go-ipld-format"
8
- mh "github.com/multiformats/go-multihash"
9
8
)
10
9
11
- type Blob []byte
10
+ type Blob struct {
11
+ rawData []byte
12
+ cid cid.Cid
13
+ }
12
14
13
- func (b Blob ) Cid () cid.Cid {
14
- c , _ := cid.Prefix {
15
- MhType : mh .SHA1 ,
16
- MhLength : - 1 ,
17
- Codec : cid .GitRaw ,
18
- Version : 1 ,
19
- }.Sum ([]byte (b ))
20
- return c
15
+ func (b * Blob ) Cid () cid.Cid {
16
+ return b .cid
21
17
}
22
18
23
- func (b Blob ) Copy () node.Node {
24
- out := make ([]byte , len (b ))
25
- copy (out , b )
26
- return Blob (out )
19
+ func (b * Blob ) Copy () node.Node {
20
+ nb := * b
21
+ return & nb
27
22
}
28
23
29
- func (b Blob ) Links () []* node.Link {
24
+ func (b * Blob ) Links () []* node.Link {
30
25
return nil
31
26
}
32
27
33
- func (b Blob ) Resolve (_ []string ) (interface {}, []string , error ) {
28
+ func (b * Blob ) Resolve (_ []string ) (interface {}, []string , error ) {
34
29
return nil , nil , errors .New ("no such link" )
35
30
}
36
31
37
- func (b Blob ) ResolveLink (_ []string ) (* node.Link , []string , error ) {
32
+ func (b * Blob ) ResolveLink (_ []string ) (* node.Link , []string , error ) {
38
33
return nil , nil , errors .New ("no such link" )
39
34
}
40
35
41
- func (b Blob ) Loggable () map [string ]interface {} {
36
+ func (b * Blob ) Loggable () map [string ]interface {} {
42
37
return map [string ]interface {}{
43
38
"type" : "git_blob" ,
44
39
}
45
40
}
46
41
47
- func (b Blob ) RawData () []byte {
48
- return []byte (b )
42
+ func (b * Blob ) RawData () []byte {
43
+ return []byte (b . rawData )
49
44
}
50
45
51
- func (b Blob ) Size () (uint64 , error ) {
52
- return uint64 (len (b )), nil
46
+ func (b * Blob ) Size () (uint64 , error ) {
47
+ return uint64 (len (b . rawData )), nil
53
48
}
54
49
55
- func (b Blob ) Stat () (* node.NodeStat , error ) {
50
+ func (b * Blob ) Stat () (* node.NodeStat , error ) {
56
51
return & node.NodeStat {}, nil
57
52
}
58
53
59
- func (b Blob ) String () string {
54
+ func (b * Blob ) String () string {
60
55
return "[git blob]"
61
56
}
62
57
63
- func (b Blob ) Tree (p string , depth int ) []string {
58
+ func (b * Blob ) Tree (p string , depth int ) []string {
64
59
return nil
65
60
}
66
61
67
- func (b Blob ) GitSha () []byte {
62
+ func (b * Blob ) GitSha () []byte {
68
63
return cidToSha (b .Cid ())
69
64
}
70
65
71
- var _ node.Node = (Blob )(nil )
66
+ var _ node.Node = (* Blob )(nil )
0 commit comments