Commit 66af0391 authored by Lars Gierth's avatar Lars Gierth

coreapi: make the interfaces path centric

The new coreiface.Path maps a path to the cid.Cid
resulting from a full path resolution.

The path is internally represented as a go-ipfs/path.Path,
but that doesn't matter to the outside.

Apart from the path-to-CID mapping, it also aims to hold all
resolved segment CIDs of the path. Right now it only exposes
Root(), and only for flat paths a la /ipfs/Qmfoo. In other cases,
the root is nil.

In the future, resolution will internally use
go-ipfs/path.Resolver.ResolvePathComponents and thus always return
the proper resolved segments, via Root(), or a future Segments() func.

- Add coreiface.Path with Cid() and Root().
- Add CoreAPI.ResolvePath() for getting a coreiface.Path.
- All functions now expect and return coreiface.Path.
- Add ParsePath() and ParseCid() for constructing a coreiface.Path.
- Add coreiface.Node and Link which are simply go-ipld-node.Node and Link.
- Add CoreAPI.ResolveNode() for getting a Node from a Path.

License: MIT
Signed-off-by: default avatarLars Gierth <larsg@systemli.org>
parent e69000d4
...@@ -9,6 +9,16 @@ import ( ...@@ -9,6 +9,16 @@ import (
ipld "gx/ipfs/QmYDscK7dmdo2GZ9aumS8s5auUUAH5mR1jvj5pYhWusfK7/go-ipld-node" ipld "gx/ipfs/QmYDscK7dmdo2GZ9aumS8s5auUUAH5mR1jvj5pYhWusfK7/go-ipld-node"
) )
type Path interface {
String() string
Cid() *cid.Cid
Root() *cid.Cid
Resolved() bool
}
// TODO: should we really copy these?
// if we didn't, godoc would generate nice links straight to go-ipld-node
type Node ipld.Node
type Link ipld.Link type Link ipld.Link
type Reader interface { type Reader interface {
...@@ -18,12 +28,14 @@ type Reader interface { ...@@ -18,12 +28,14 @@ type Reader interface {
type CoreAPI interface { type CoreAPI interface {
Unixfs() UnixfsAPI Unixfs() UnixfsAPI
ResolvePath(context.Context, Path) (Path, error)
ResolveNode(context.Context, Path) (Node, error)
} }
type UnixfsAPI interface { type UnixfsAPI interface {
Add(context.Context, io.Reader) (*cid.Cid, error) Add(context.Context, io.Reader) (Path, error)
Cat(context.Context, string) (Reader, error) Cat(context.Context, Path) (Reader, error)
Ls(context.Context, string) ([]*Link, error) Ls(context.Context, Path) ([]*Link, error)
} }
// type ObjectAPI interface { // type ObjectAPI interface {
...@@ -49,5 +61,4 @@ type UnixfsAPI interface { ...@@ -49,5 +61,4 @@ type UnixfsAPI interface {
// } // }
var ErrIsDir = errors.New("object is a directory") var ErrIsDir = errors.New("object is a directory")
var ErrIsNonDag = errors.New("not a merkledag object")
var ErrOffline = errors.New("can't resolve, ipfs node is offline") var ErrOffline = errors.New("can't resolve, ipfs node is offline")
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