Skip to content

Commit 0052a62

Browse files
committed
fix: return nil Bytes() if the Cid in undef
1 parent 802b455 commit 0052a62

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

cid.go

+6
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,13 @@ func (c Cid) Hash() mh.Multihash {
378378
// Bytes returns the byte representation of a Cid.
379379
// The output of bytes can be parsed back into a Cid
380380
// with Cast().
381+
//
382+
// If c.Defined() == false, it return a nil slice and may not
383+
// be parsable with Cast().
381384
func (c Cid) Bytes() []byte {
385+
if !c.Defined() {
386+
return nil
387+
}
382388
return []byte(c.str)
383389
}
384390

0 commit comments

Comments
 (0)