Skip to content

Commit 5ff5074

Browse files
committed
Tweak return parameters of Multihash.Parts()
1 parent 4e40cd1 commit 5ff5074

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

multihash.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,15 @@ func FromBinary(v string) Multihash {
247247
return Multihash{v}
248248
}
249249

250-
// Parts returns the components of the Multihash (Code, Name, Digest)
251-
func (m Multihash) Parts() (uint64, int, string) {
252-
// Note: no need to check for errors as the New method guarantees
250+
// Parts returns the components of the Multihash: Code & Digest
251+
// The length part can be derived from the Digest length
252+
func (m Multihash) Parts() (uint64, string) {
253+
// Note: no need to check for errors as the FromBinary method guarantees
253254
// the string can be parsed
254-
i := 0
255-
codec, l := strbinary.Uvarint(m.s)
256-
i += l
257-
digestLen, l := strbinary.Uvarint(m.s[i:])
258-
i += l
259-
return codec, int(digestLen), m.s[i:]
255+
codec, i := strbinary.Uvarint(m.s)
256+
// skip over Length component, no need to read it
257+
i += strbinary.UvarintLen(m.s[i:])
258+
return codec, m.s[i:]
260259
}
261260

262261
// Cast casts a buffer onto a multihash, and returns an error

0 commit comments

Comments
 (0)