Slightly more documentation comment.

This commit is contained in:
Eric Myhre
2020-05-02 00:52:07 +02:00
parent 266e76d591
commit 628a0123ed

11
cid.go
View File

@@ -409,12 +409,19 @@ func (c Cid) Bytes() []byte {
return []byte(c.str)
}
// ByteLen returns len(c.Bytes()) without an allocation
// ByteLen returns the length of the CID in bytes.
// It's equivalent to `len(c.Bytes())`, but works without an allocation,
// and should therefore be preferred.
//
// (See also the WriteTo method for other important operations that work without allocation.)
func (c Cid) ByteLen() int {
return len(c.str)
}
// WriteTo writes the cids bytes to the given writer
// WriteTo writes the CID bytes to the given writer.
// This method works without incurring any allocation.
//
// (See also the ByteLen method for other important operations that work without allocation.)
func (c Cid) WriteTo(w io.Writer) (int, error) {
return io.WriteString(w, c.str)
}