1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-08-24 10:32:01 +08:00
Files
Hannah Howard f63a997c35 IPLD Prime In IPFS: Target Merge Branch (#7976)
* feat: switch to using go-ipld-prime for codecs, path resolution, and the `dag put/get` commands
* fix: `dag put/get` not roundtripping due to an extra new line being added (https://github.com/ipfs/go-ipfs/issues/3503)

More detailed information is in the CHANGELOG.md file. Very high level:
* IPLD codecs (and their plugins) must use go-ipld-prime
* Added support for the dag-json codec
* `dag get/put` use IPLD codec names from the multicodec table
* `dag get` defaults to dag-json output instead of json, but may output with other codecs
* Data model pathing can be achieved using the /ipld prefix. For example, you can use `/ipld/QmFoo/Links/0/Hash` to traverse through a DagPB node
* With `dag get/put` the DagPB field names have been changed to match the ones in the protobuf listed in the specification

Co-authored-by: hannahhoward <hannah@hannahhoward.net>
Co-authored-by: Daniel Martí <mvdan@mvdan.cc>
Co-authored-by: acruikshank <acruikshank@example.com>
Co-authored-by: Steven Allen <steven@stebalien.com>
Co-authored-by: Will Scott <will.scott@protocol.ai>
Co-authored-by: Will Scott <will@cypherpunk.email>
Co-authored-by: Rod Vagg <rod@vagg.org>
Co-authored-by: Adin Schmahmann <adin.schmahmann@gmail.com>
Co-authored-by: Eric Myhre <hash@exultant.us>
2021-08-17 13:32:49 -04:00

55 lines
1.2 KiB
Go

package git
import (
"compress/zlib"
"io"
"github.com/ipfs/go-ipfs/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)
}