multihash implementation in Go
go get github.com/multiformats/go-multihash
package main
import (
"encoding/hex"
"fmt"
"github.com/multiformats/go-multihash"
)
func main() {
// ignores errors for simplicity.
// don't do that at home.
buf, _ := hex.DecodeString("0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")
mhbuf, _ := multihash.EncodeName(buf, "sha1");
mhhex := hex.EncodeToString(mhbuf)
fmt.Printf("hex: %v\n", mhhex);
o, _ := multihash.Decode(mhbuf);
mhhex = hex.EncodeToString(o.Digest);
fmt.Printf("obj: %v 0x%x %d %s\n", o.Name, o.Code, o.Length, mhhex);
}
Run test/foo.go
> cd test/
> go build
> ./test
hex: 11140beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
obj: sha1 0x11 20 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
Captain: @Kubuxu.
Contributions welcome. Please check out the issues.
Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.
Small note: If editing the README, please conform to the standard-readme specification.
MIT © 2014 Juan Batiz-Benet