unixfs.go 2.07 KB
Newer Older
1 2 3 4
package iface

import (
	"context"
Łukasz Magiera's avatar
Łukasz Magiera committed
5
	"github.com/ipfs/interface-go-ipfs-core/options"
Łukasz Magiera's avatar
Łukasz Magiera committed
6
	path "github.com/ipfs/interface-go-ipfs-core/path"
7

Łukasz Magiera's avatar
Łukasz Magiera committed
8 9
	"github.com/ipfs/go-cid"
	"github.com/ipfs/go-ipfs-files"
10 11
)

12 13
type AddEvent struct {
	Name  string
Łukasz Magiera's avatar
Łukasz Magiera committed
14 15 16
	Path  path.ResolvedPath `json:",omitempty"`
	Bytes int64              `json:",omitempty"`
	Size  string             `json:",omitempty"`
17 18
}

Steven Allen's avatar
Steven Allen committed
19
// FileType is an enum of possible UnixFS file types.
20 21 22
type FileType int32

const (
Steven Allen's avatar
Steven Allen committed
23 24 25 26 27 28 29 30 31
	// TUnknown means the file type isn't known (e.g., it hasn't been
	// resolved).
	TUnknown FileType = iota
	// TFile is a regular file.
	TFile
	// TDirectory is a directory.
	TDirectory
	// TSymlink is a symlink.
	TSymlink
32 33
)

Steven Allen's avatar
Steven Allen committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
func (t FileType) String() string {
	switch t {
	case TUnknown:
		return "unknown"
	case TFile:
		return "file"
	case TDirectory:
		return "directory"
	case TSymlink:
		return "symlink"
	default:
		return "<unknown file type>"
	}
}

Steven Allen's avatar
Steven Allen committed
49 50 51 52 53 54 55 56
// DirEntry is a directory entry returned by `Ls`.
type DirEntry struct {
	Name string
	Cid  cid.Cid

	// Only filled when asked to resolve the directory entry.
	Size   uint64   // The size of the file in bytes (or the size of the symlink).
	Type   FileType // The type of the file.
57
	Target string   // The symlink target (if a symlink).
58 59 60 61

	Err error
}

62
// UnixfsAPI is the basic interface to immutable files in IPFS
63
// NOTE: This API is heavily WIP, things are guaranteed to break frequently
64 65
type UnixfsAPI interface {
	// Add imports the data from the reader into merkledag file
Łukasz Magiera's avatar
Łukasz Magiera committed
66 67
	//
	// TODO: a long useful comment on how to use this for many different scenarios
Łukasz Magiera's avatar
Łukasz Magiera committed
68
	Add(context.Context, files.Node, ...options.UnixfsAddOption) (path.ResolvedPath, error)
69

Łukasz Magiera's avatar
Łukasz Magiera committed
70 71 72 73
	// Get returns a read-only handle to a file tree referenced by a path
	//
	// Note that some implementations of this API may apply the specified context
	// to operations performed on the returned file
Łukasz Magiera's avatar
Łukasz Magiera committed
74
	Get(context.Context, path.Path) (files.Node, error)
Łukasz Magiera's avatar
Łukasz Magiera committed
75

76 77
	// Ls returns the list of links in a directory. Links aren't guaranteed to be
	// returned in order
Łukasz Magiera's avatar
Łukasz Magiera committed
78
	Ls(context.Context, path.Path, ...options.UnixfsLsOption) (<-chan DirEntry, error)
79
}