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

feat: files (mfs) api #54

Closed
wants to merge 5 commits 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
3 changes: 3 additions & 0 deletions coreapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ type CoreAPI interface {
// PubSub returns an implementation of PubSub API
PubSub() PubSubAPI

// Files returns an implementation of Files API
Files() FilesAPI

// ResolvePath resolves the path using Unixfs resolver
ResolvePath(context.Context, path.Path) (path.Resolved, error)

Expand Down
88 changes: 88 additions & 0 deletions files.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package iface

import (
"context"
"io"

"github.com/ipfs/go-cid"
"github.com/ipfs/go-cidutil/cidenc"
"github.com/ipfs/go-mfs"
)

type FilesCopyOptions struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs. Lots of docs.

Flush bool
}

type FilesMoveOptions struct {
Flush bool
}

type FilesListOptions struct {
CidEncoder cidenc.Encoder
Long bool
}

type FilesRemoveOptions struct {
Force bool
Recursive bool
}

type FilesStatOptions struct {
CidEncoder cidenc.Encoder
WithLocality bool
}

type FilesWriteOptions struct {
Create bool
MakeParents bool
Truncate bool
Flush bool
RawLeaves bool
RawLeavesOverride bool
Offset int64
// Count is the number of bytes to write. 0 (default) writes everything.
Count int64
CidBuilder cid.Builder
}

type FilesReadOptions struct {
Offset int64
// Count is the number of bytes to read. 0 (default) reads everything.
Count int64
}

type FilesMkdirOptions struct {
MakeParents bool
Flush bool
CidBuilder cid.Builder
}

type FilesChangeCidOptions struct {
Flush bool
CidBuilder cid.Builder
}

type FileInfo struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs

Cid cid.Cid
Size uint64
CumulativeSize uint64
Blocks int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why we called this "blocks". Let's call it what it is, Children (NumChildren?).

Type string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the file types from unixfs.go.

WithLocality bool `json:",omitempty"`
Local bool `json:",omitempty"`
SizeLocal uint64 `json:",omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. I remember not liking this when it first came up. Can we come up with a better (internal) API and translate back at the edges? I'll think about this a bit but proposals are very welcome. For historical context: ipfs/kubo#4638

}

// FilesAPI specifies an interface to interact with the Mutable File System
// layer.
type FilesAPI interface {
Copy(ctx context.Context, src, dst string, opts *FilesCopyOptions) error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the functional options pattern we use in the other APIs. It allows us to add new complicated options (with logic) while retaining backwards compatibility.

See: https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis

Move(ctx context.Context, src, dst string, opts *FilesMoveOptions) error
List(ctx context.Context, path string, opts *FilesListOptions) ([]mfs.NodeListing, error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this streaming from the start. See #49

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's re-use the return type from Unixfs().Ls(). I'd rather not expose internal mfs types in this API.

Remove(ctx context.Context, path string, opts *FilesRemoveOptions) error
Stat(ctx context.Context, path string, opts *FilesStatOptions) (*FileInfo, error)
Read(ctx context.Context, path string, opts *FilesReadOptions) (io.ReadCloser, error)
Write(ctx context.Context, path string, r io.Reader, opts *FilesWriteOptions) error
Mkdir(ctx context.Context, path string, opts *FilesMkdirOptions) error
Flush(ctx context.Context, path string) (cid.Cid, error)
}
21 changes: 15 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
module github.com/ipfs/interface-go-ipfs-core

require (
github.com/fd/go-nat v1.0.0 // indirect
github.com/gxed/pubsub v0.0.0-20180201040156-26ebdf44f824 // indirect
github.com/ipfs/go-cid v0.0.3
github.com/ipfs/go-ipfs-files v0.0.2
github.com/ipfs/go-ipld-cbor v0.0.1
github.com/ipfs/go-ipld-format v0.0.1
github.com/ipfs/go-merkledag v0.0.3
github.com/ipfs/go-path v0.0.3
github.com/ipfs/go-unixfs v0.0.4
github.com/ipfs/go-cidutil v0.0.2
github.com/ipfs/go-ipfs-files v0.0.3
github.com/ipfs/go-ipfs-flags v0.0.1 // indirect
github.com/ipfs/go-ipld-cbor v0.0.2
github.com/ipfs/go-ipld-format v0.0.2
github.com/ipfs/go-merkledag v0.1.0
github.com/ipfs/go-mfs v0.1.1
github.com/ipfs/go-path v0.0.7
github.com/ipfs/go-unixfs v0.1.0
github.com/libp2p/go-libp2p-core v0.2.2
github.com/multiformats/go-multiaddr v0.0.4
github.com/multiformats/go-multihash v0.0.7
github.com/whyrusleeping/go-smux-multiplex v3.0.16+incompatible // indirect
github.com/whyrusleeping/go-smux-multistream v2.0.2+incompatible // indirect
github.com/whyrusleeping/go-smux-yamux v2.0.9+incompatible // indirect
github.com/whyrusleeping/yamux v1.1.5 // indirect
)

go 1.12
Loading