4d15ae8a85 | ||
---|---|---|
.. | ||
.gitignore | ||
.travis.yml | ||
LICENSE | ||
README.md | ||
codecs.go | ||
generate.go | ||
generate.sh | ||
multicodec.go |
README.md
go-multicodec
Go utility library to provide encoding and decoding of multicodec values.
Table of Contents
Install
go-multicodec
is a standard Go module which can be installed with:
go get github.com/wealdtech/go-multicodec
Usage
Example
import (
"bytes"
"encoding/hex"
"errors"
multicodec "github.com/wealdtech/go-multicodec"
)
func main() {
// Data in this case is an IPFS hash in multihash format with a dag-pb content type
data, err := hex.DecodeString("70122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f")
if err != nil {
panic(err)
}
// Add the "ipfs-ns" namespace codec
dataWithCodec, err := multicodec.AddCodec("ipfs-ns", data)
if err != nil {
panic(err)
}
if !multicodec.IsCodec("ipfs-ns", dataWithCodec) {
panic(errors.New("data does not have correct codec prefix"))
}
// Remove the codec
dataWithoutCodec, _, err := multicodec.RemoveCodec(dataWithCodec)
if err != nil {
panic(err)
}
if !bytes.Equal(data, dataWithoutCodec) {
panic(errors.New("data mismatch"))
}
}
Maintainers
Jim McDonald: @mcdee.
Contribute
Contributions welcome. Please check out the issues.
License
Apache-2.0 © 2019 Weald Technology Trading Ltd