Commit 67a2bcf7 authored by Kevin Atkinson's avatar Kevin Atkinson

Change 'Nil' constant to 'Undef'.

parent 643f78a8
...@@ -36,7 +36,7 @@ func (p Prefix) WithCodec(c uint64) Builder { ...@@ -36,7 +36,7 @@ func (p Prefix) WithCodec(c uint64) Builder {
func (p V0Builder) Sum(data []byte) (Cid, error) { func (p V0Builder) Sum(data []byte) (Cid, error) {
hash, err := mh.Sum(data, mh.SHA2_256, -1) hash, err := mh.Sum(data, mh.SHA2_256, -1)
if err != nil { if err != nil {
return Nil, err return Undef, err
} }
return NewCidV0(hash), nil return NewCidV0(hash), nil
} }
...@@ -59,7 +59,7 @@ func (p V1Builder) Sum(data []byte) (Cid, error) { ...@@ -59,7 +59,7 @@ func (p V1Builder) Sum(data []byte) (Cid, error) {
} }
hash, err := mh.Sum(data, p.MhType, mhLen) hash, err := mh.Sum(data, p.MhType, mhLen)
if err != nil { if err != nil {
return Nil, err return Undef, err
} }
return NewCidV1(p.Codec, hash), nil return NewCidV1(p.Codec, hash), nil
} }
......
...@@ -157,9 +157,9 @@ func NewCidV1(codecType uint64, mhash mh.Multihash) Cid { ...@@ -157,9 +157,9 @@ func NewCidV1(codecType uint64, mhash mh.Multihash) Cid {
// a multicodec-packed content type) and a Multihash. // a multicodec-packed content type) and a Multihash.
type Cid struct{ str string } type Cid struct{ str string }
// Nil can be used to represent a nil Cid, using Cid{} directly is // Undef can be used to represent a nil or undefined Cid, using Cid{}
// also acceptable. // directly is also acceptable.
var Nil = Cid{} var Undef = Cid{}
// Defined returns true if a Cid is defined // Defined returns true if a Cid is defined
// Calling any other methods on an undefined Cid will result in // Calling any other methods on an undefined Cid will result in
...@@ -184,7 +184,7 @@ func Parse(v interface{}) (Cid, error) { ...@@ -184,7 +184,7 @@ func Parse(v interface{}) (Cid, error) {
case Cid: case Cid:
return v2, nil return v2, nil
default: default:
return Nil, fmt.Errorf("can't parse %+v as Cid", v2) return Undef, fmt.Errorf("can't parse %+v as Cid", v2)
} }
} }
...@@ -202,13 +202,13 @@ func Parse(v interface{}) (Cid, error) { ...@@ -202,13 +202,13 @@ func Parse(v interface{}) (Cid, error) {
// as B58-encoded multihashes. // as B58-encoded multihashes.
func Decode(v string) (Cid, error) { func Decode(v string) (Cid, error) {
if len(v) < 2 { if len(v) < 2 {
return Nil, ErrCidTooShort return Undef, ErrCidTooShort
} }
if len(v) == 46 && v[:2] == "Qm" { if len(v) == 46 && v[:2] == "Qm" {
hash, err := mh.FromB58String(v) hash, err := mh.FromB58String(v)
if err != nil { if err != nil {
return Nil, err return Undef, err
} }
return NewCidV0(hash), nil return NewCidV0(hash), nil
...@@ -216,7 +216,7 @@ func Decode(v string) (Cid, error) { ...@@ -216,7 +216,7 @@ func Decode(v string) (Cid, error) {
_, data, err := mbase.Decode(v) _, data, err := mbase.Decode(v)
if err != nil { if err != nil {
return Nil, err return Undef, err
} }
return Cast(data) return Cast(data)
...@@ -270,7 +270,7 @@ func Cast(data []byte) (Cid, error) { ...@@ -270,7 +270,7 @@ func Cast(data []byte) (Cid, error) {
if len(data) == 34 && data[0] == 18 && data[1] == 32 { if len(data) == 34 && data[0] == 18 && data[1] == 32 {
h, err := mh.Cast(data) h, err := mh.Cast(data)
if err != nil { if err != nil {
return Nil, err return Undef, err
} }
return NewCidV0(h), nil return NewCidV0(h), nil
...@@ -278,22 +278,22 @@ func Cast(data []byte) (Cid, error) { ...@@ -278,22 +278,22 @@ func Cast(data []byte) (Cid, error) {
vers, n := binary.Uvarint(data) vers, n := binary.Uvarint(data)
if err := uvError(n); err != nil { if err := uvError(n); err != nil {
return Nil, err return Undef, err
} }
if vers != 1 { if vers != 1 {
return Nil, fmt.Errorf("expected 1 as the cid version number, got: %d", vers) return Undef, fmt.Errorf("expected 1 as the cid version number, got: %d", vers)
} }
_, cn := binary.Uvarint(data[n:]) _, cn := binary.Uvarint(data[n:])
if err := uvError(cn); err != nil { if err := uvError(cn); err != nil {
return Nil, err return Undef, err
} }
rest := data[n+cn:] rest := data[n+cn:]
h, err := mh.Cast(rest) h, err := mh.Cast(rest)
if err != nil { if err != nil {
return Nil, err return Undef, err
} }
return Cid{string(data[0 : n+cn+len(h)])}, nil return Cid{string(data[0 : n+cn+len(h)])}, nil
...@@ -475,7 +475,7 @@ type Prefix struct { ...@@ -475,7 +475,7 @@ type Prefix struct {
func (p Prefix) Sum(data []byte) (Cid, error) { func (p Prefix) Sum(data []byte) (Cid, error) {
hash, err := mh.Sum(data, p.MhType, p.MhLength) hash, err := mh.Sum(data, p.MhType, p.MhLength)
if err != nil { if err != nil {
return Nil, err return Undef, err
} }
switch p.Version { switch p.Version {
...@@ -484,7 +484,7 @@ func (p Prefix) Sum(data []byte) (Cid, error) { ...@@ -484,7 +484,7 @@ func (p Prefix) Sum(data []byte) (Cid, error) {
case 1: case 1:
return NewCidV1(p.Codec, hash), nil return NewCidV1(p.Codec, hash), nil
default: default:
return Nil, fmt.Errorf("invalid cid version") return Undef, fmt.Errorf("invalid cid version")
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment