unixfs.go 1.49 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

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

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

19 20 21 22 23 24 25 26 27 28 29
type FileType int32

const (
	TRaw       = FileType(unixfs.TRaw)
	TFile      = FileType(unixfs.TFile)
	TDirectory = FileType(unixfs.TDirectory)
	TMetadata  = FileType(unixfs.TMetadata)
	TSymlink   = FileType(unixfs.TSymlink)
	THAMTShard = FileType(unixfs.THAMTShard)
)

30 31 32
type LsLink struct {
	Link *ipld.Link
	Size uint64
33
	Type FileType
34 35 36 37

	Err error
}

38
// UnixfsAPI is the basic interface to immutable files in IPFS
39
// NOTE: This API is heavily WIP, things are guaranteed to break frequently
40 41
type UnixfsAPI interface {
	// Add imports the data from the reader into merkledag file
Łukasz Magiera's avatar
Łukasz Magiera committed
42 43
	//
	// TODO: a long useful comment on how to use this for many different scenarios
44
	Add(context.Context, files.Node, ...options.UnixfsAddOption) (ResolvedPath, error)
45

Łukasz Magiera's avatar
Łukasz Magiera committed
46 47 48 49
	// 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
50
	Get(context.Context, Path) (files.Node, error)
Łukasz Magiera's avatar
Łukasz Magiera committed
51

52 53
	// Ls returns the list of links in a directory. Links aren't guaranteed to be
	// returned in order
54
	Ls(context.Context, Path, ...options.UnixfsLsOption) (<-chan LsLink, error)
55
}