forked from bittorrent/go-btfs-files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.go
104 lines (84 loc) · 2.57 KB
/
file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package files
import (
"errors"
"io"
"os"
)
var (
ErrNotDirectory = errors.New("file isn't a directory")
ErrNotReader = errors.New("file isn't a regular file")
ErrNotSupported = errors.New("operation not supported")
)
// Node is a common interface for files, directories and other special files
type Node interface {
io.Closer
// Size returns size of this file (if this file is a directory, total size of
// all files stored in the tree should be returned). Some implementations may
// choose not to implement this
Size() (int64, error)
}
// Node represents a regular Unix file
type File interface {
Node
io.Reader
io.Seeker
}
// DirEntry exposes information about a directory entry
type DirEntry interface {
// Name returns base name of this entry, which is the base name of referenced
// file
Name() string
// Node returns the file referenced by this DirEntry
Node() Node
}
// DirIterator is a iterator over directory entries.
// See Directory.Entries for more
type DirIterator interface {
// DirEntry holds information about current directory entry.
// Note that after creating new iterator you MUST call Next() at least once
// before accessing these methods. Calling these methods without prior calls
// to Next() and after Next() returned false may result in undefined behavior
DirEntry
// Next advances iterator to the next file.
Next() bool
// Err may return an error after previous call to Next() returned `false`.
// If previous call to Next() returned `true`, Err() is guaranteed to
// return nil
Err() error
// BreadthFirstTraversal indicates that the current DirIterator
// instance will be used to traverse in breadth first walk9ng method
BreadthFirstTraversal()
}
// Directory is a special file which can link to any number of files.
type Directory interface {
Node
// Entries returns a stateful iterator over directory entries. The iterator
// may consume the Directory state so it must be called only once (this
// applies specifically to the multipartIterator).
//
// Example usage:
//
// it := dir.Entries()
// for it.Next() {
// name := it.Name()
// file := it.Node()
// [...]
// }
// if it.Err() != nil {
// return err
// }
//
// Note that you can't store the result of it.Node() and use it after
// advancing the iterator
Entries() DirIterator
SetSize(int64) error
IsReedSolomon() bool
}
// FileInfo exposes information on files in local filesystem
type FileInfo interface {
Node
// AbsPath returns full real file path.
AbsPath() string
// Stat returns os.Stat of this file, may be nil for some files
Stat() os.FileInfo
}