-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_system.go
79 lines (70 loc) · 1.93 KB
/
file_system.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
package filesystem
import (
"context"
"io"
"io/fs"
)
// File abstracts a file
type File interface {
fs.File
io.ReaderAt
io.Writer
io.Seeker
Truncate(int64) error
Sync() error
Name() string
}
// FilesInfo is a slice of FileInfo
type FilesInfo []FileInfo
// FullNames returns a slice of full names derived from the receiver slice
func (fsi FilesInfo) FullNames() []string {
res := make([]string, len(fsi))
for i, el := range fsi {
res[i] = el.FullName()
}
return res
}
// FileInfo abstracts file information
type FileInfo interface {
fs.FileInfo
FS() FileSystem
FullName() string
}
// DirEntry abstracts directory walkDirEntry
type DirEntry interface {
fs.DirEntry
FullName() string
}
// WalkDirFunc is a wrapper around fs.WalkDirFunc
type WalkDirFunc func(string, DirEntry, error) error
// FileNameData represents file name and data
type FileNameData struct {
Name string
Data []byte
}
// FileSystem abstracts a file system
type FileSystem interface {
Create(context.Context, string) (File, error)
Open(context.Context, string) (File, error)
OpenW(context.Context, string) (File, error)
ReadFile(context.Context, string) ([]byte, error)
WriteFile(context.Context, string, []byte) error
WriteFiles(context.Context, []FileNameData) error
Reader(context.Context, string) (io.ReadCloser, error)
Exists(context.Context, string) (bool, error)
MakePathAll(context.Context, string) error
Remove(context.Context, string) error
RemoveFiles(context.Context, []string) ([]string, error)
RemoveAll(context.Context, string) error
IsNotExist(error) bool
IsEmptyPath(context.Context, string) (bool, error)
PreparePath(context.Context, string) (string, error)
Rename(context.Context, string, string) error
Stat(context.Context, string) (FileInfo, error)
ReadDir(context.Context, string) (FilesInfo, error)
WalkDir(context.Context, string, WalkDirFunc) error
Join(...string) string
Dir(string) string
Ext(string) string
Base(string) string
}