unixfs.go 2 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"
6

Steven Allen's avatar
Steven Allen committed
7 8
	cid "github.com/ipfs/go-cid"
	files "github.com/ipfs/go-ipfs-files"
9 10
)

11 12
type AddEvent struct {
	Name  string
13 14 15
	Path  ResolvedPath `json:",omitempty"`
	Bytes int64        `json:",omitempty"`
	Size  string       `json:",omitempty"`
16 17
}

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

const (
Steven Allen's avatar
Steven Allen committed
22 23 24 25 26 27 28 29 30
	// 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
31 32
)

Steven Allen's avatar
Steven Allen committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
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
48 49 50 51 52 53 54 55
// 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.
56
	Target string   // The symlink target (if a symlink).
57 58 59 60

	Err error
}

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

Łukasz Magiera's avatar
Łukasz Magiera committed
69 70 71 72
	// 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
73
	Get(context.Context, Path) (files.Node, error)
Łukasz Magiera's avatar
Łukasz Magiera committed
74

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