Use optimized multihash method for parsing

This commit is contained in:
whyrusleeping
2019-11-11 16:33:49 -08:00
parent 16bbe1cf14
commit cf8cf8856e
3 changed files with 7 additions and 4 deletions

5
cid.go
View File

@@ -610,13 +610,12 @@ func CidFromBytes(data []byte) (int, Cid, error) {
return 0, Undef, err
}
mhr := mh.NewReader(bytes.NewReader(data[n+cn:]))
h, err := mhr.ReadMultihash()
mhnr, _, err := mh.MHFromBytes(data[n+cn:])
if err != nil {
return 0, Undef, err
}
l := n + cn + len(h)
l := n + cn + mhnr
return l, Cid{string(data[0:l])}, nil
}

4
go.mod
View File

@@ -2,5 +2,7 @@ module github.com/ipfs/go-cid
require (
github.com/multiformats/go-multibase v0.0.1
github.com/multiformats/go-multihash v0.0.8
github.com/multiformats/go-multihash v0.0.9
)
go 1.13

2
go.sum
View File

@@ -20,6 +20,8 @@ github.com/multiformats/go-multihash v0.0.1 h1:HHwN1K12I+XllBCrqKnhX949Orn4oawPk
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
github.com/multiformats/go-multihash v0.0.8 h1:wrYcW5yxSi3dU07n5jnuS5PrNwyHy0zRHGVoUugWvXg=
github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.0.9 h1:aoijQXYYl7Xtb2pUUP68R+ys1TlnlR3eX6wmozr0Hp4=
github.com/multiformats/go-multihash v0.0.9/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=