-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
git.go
54 lines (41 loc) · 1.18 KB
/
git.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
package git
import (
"compress/zlib"
"io"
"github.com/ipfs/kubo/plugin"
// Note that depending on this package registers it's multicodec encoder and decoder.
git "github.com/ipfs/go-ipld-git"
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/multicodec"
mc "github.com/multiformats/go-multicodec"
)
// Plugins is exported list of plugins that will be loaded.
var Plugins = []plugin.Plugin{
&gitPlugin{},
}
type gitPlugin struct{}
var _ plugin.PluginIPLD = (*gitPlugin)(nil)
func (*gitPlugin) Name() string {
return "ipld-git"
}
func (*gitPlugin) Version() string {
return "0.0.1"
}
func (*gitPlugin) Init(_ *plugin.Environment) error {
return nil
}
func (*gitPlugin) Register(reg multicodec.Registry) error {
// register a custom identifier in the reserved range for import of "zlib-encoded git objects."
reg.RegisterDecoder(uint64(mc.ReservedStart+mc.GitRaw), decodeZlibGit)
reg.RegisterEncoder(uint64(mc.GitRaw), git.Encode)
reg.RegisterDecoder(uint64(mc.GitRaw), git.Decode)
return nil
}
func decodeZlibGit(na ipld.NodeAssembler, r io.Reader) error {
rc, err := zlib.NewReader(r)
if err != nil {
return err
}
defer rc.Close()
return git.Decode(na, rc)
}