Skip to content

Commit

Permalink
Merge pull request #85 from ipfs/feat/cidv1-default-base32
Browse files Browse the repository at this point in the history
default cidv1 to base32
  • Loading branch information
Stebalien committed May 13, 2019
2 parents e7e67e0 + b16425b commit b1cc3e4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ This will make sure that dependencies are rewritten to known working versions.

```go
// Create a cid from a marshaled string
c, err := cid.Decode("zdvgqEMYmNeH5fKciougvQcfzMcNjF3Z1tPouJ8C7pc3pe63k")
c, err := cid.Decode("bafzbeigai3eoy2ccc7ybwjfz5r3rdxqrinwi4rwytly24tdbh6yk7zslrm")
if err != nil {...}

fmt.Println("Got CID: ", c)
Expand Down
2 changes: 1 addition & 1 deletion cid.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func (c Cid) String() string {
case 0:
return c.Hash().B58String()
case 1:
mbstr, err := mbase.Encode(mbase.Base58BTC, c.Bytes())
mbstr, err := mbase.Encode(mbase.Base32, c.Bytes())
if err != nil {
panic("should not error with hardcoded mbase: " + err.Error())
}
Expand Down
10 changes: 5 additions & 5 deletions cid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,25 +438,25 @@ func TestHexDecode(t *testing.T) {
t.Fatal(err)
}

if c.String() != "zb2rhhFAEMepUBbGyP1k8tGfz7BSciKXP6GHuUeUsJBaK6cqG" {
if c.String() != "bafkreie5qrjvaw64n4tjm6hbnm7fnqvcssfed4whsjqxzslbd3jwhsk3mm" {
t.Fatal("hash value failed to round trip decoding from hex")
}
}

func ExampleDecode() {
encoded := "zb2rhhFAEMepUBbGyP1k8tGfz7BSciKXP6GHuUeUsJBaK6cqG"
encoded := "bafkreie5qrjvaw64n4tjm6hbnm7fnqvcssfed4whsjqxzslbd3jwhsk3mm"
c, err := Decode(encoded)
if err != nil {
fmt.Printf("Error: %s", err)
return
}

fmt.Println(c)
// Output: zb2rhhFAEMepUBbGyP1k8tGfz7BSciKXP6GHuUeUsJBaK6cqG
// Output: bafkreie5qrjvaw64n4tjm6hbnm7fnqvcssfed4whsjqxzslbd3jwhsk3mm
}

func TestFromJson(t *testing.T) {
cval := "zb2rhhFAEMepUBbGyP1k8tGfz7BSciKXP6GHuUeUsJBaK6cqG"
cval := "bafkreie5qrjvaw64n4tjm6hbnm7fnqvcssfed4whsjqxzslbd3jwhsk3mm"
jsoncid := []byte(`{"/":"` + cval + `"}`)
var c Cid
err := json.Unmarshal(jsoncid, &c)
Expand All @@ -470,7 +470,7 @@ func TestFromJson(t *testing.T) {
}

func TestJsonRoundTrip(t *testing.T) {
exp, err := Decode("zb2rhhFAEMepUBbGyP1k8tGfz7BSciKXP6GHuUeUsJBaK6cqG")
exp, err := Decode("bafkreie5qrjvaw64n4tjm6hbnm7fnqvcssfed4whsjqxzslbd3jwhsk3mm")
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit b1cc3e4

Please sign in to comment.