unixfs.go 1.77 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
// 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.
	Target Path     // The symlink target (if a symlink).
42 43 44 45

	Err error
}

46
// UnixfsAPI is the basic interface to immutable files in IPFS
47
// NOTE: This API is heavily WIP, things are guaranteed to break frequently
48 49
type UnixfsAPI interface {
	// Add imports the data from the reader into merkledag file
Łukasz Magiera's avatar
Łukasz Magiera committed
50 51
	//
	// TODO: a long useful comment on how to use this for many different scenarios
52
	Add(context.Context, files.Node, ...options.UnixfsAddOption) (ResolvedPath, error)
53

Łukasz Magiera's avatar
Łukasz Magiera committed
54 55 56 57
	// 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
58
	Get(context.Context, Path) (files.Node, error)
Łukasz Magiera's avatar
Łukasz Magiera committed
59

60 61
	// 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
62
	Ls(context.Context, Path, ...options.UnixfsLsOption) (<-chan DirEntry, error)
63
}