Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Allow CID functions to work with non-default multibase. #9

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions path.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ func FromString(s string) Path {
}

// FromCid safely converts a cid.Cid type to a Path type.
func FromCid(c cid.Cid) Path {
return Path("/ipfs/" + c.String())
func FromCid(f func(cid.Cid) string, c cid.Cid) Path {
if f == nil {
f = (cid.Cid).String
}
return Path("/ipfs/" + f(c))
}

// Segments returns the different elements of a path
Expand Down Expand Up @@ -134,12 +137,12 @@ func ParseCidToPath(txt string) (Path, error) {
return "", ErrNoComponents
}

c, err := cid.Decode(txt)
_, err := cid.Decode(txt)
if err != nil {
return "", err
}

return FromCid(c), nil
return Path("/ipfs/" + txt), nil
}

// IsValid checks if a path is a valid ipfs Path.
Expand Down
1 change: 0 additions & 1 deletion resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func TestRecurivePathResolution(t *testing.T) {
t.Fatal(err)
}


if len(rest) != 0 {
t.Error("expected rest to be empty")
}
Expand Down