fix: return nil Bytes() if the Cid in undef

This commit is contained in:
Jorropo
2022-08-18 17:42:04 +02:00
parent 802b45594e
commit 0052a62190

6
cid.go
View File

@@ -378,7 +378,13 @@ func (c Cid) Hash() mh.Multihash {
// Bytes returns the byte representation of a Cid.
// The output of bytes can be parsed back into a Cid
// with Cast().
//
// If c.Defined() == false, it return a nil slice and may not
// be parsable with Cast().
func (c Cid) Bytes() []byte {
if !c.Defined() {
return nil
}
return []byte(c.str)
}