-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfakeFile.go
79 lines (64 loc) · 1.17 KB
/
fakeFile.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
// +build FakeFileSystem
package fs
import (
"os"
"time"
)
type File struct {
path string
size int64
mode os.FileMode
modTime time.Time
isDir bool
sys *fakeFileSystem
Content []byte
}
type FileInfo struct {
name string
size int64
mode os.FileMode
modTime time.Time
isDir bool
sys interface{}
}
func (f *File) Stat() (os.FileInfo, error) {
fi := &FileInfo{
size: int64(len(f.Content)),
}
return fi, nil
}
func (s *File) Read(p []byte) (n int, err error) {
for _, c := range s.Content {
p = append(p, byte(c))
}
return len(s.Content), nil
}
func (f *File) Close() error {
return nil
}
func (f *File) ReadAt(p []byte, offset int64) (int, error) {
/*Not implemented*/
return 0, nil
}
func (f *File) Seek(offset int64, whence int) (int64, error) {
/*Not implemented*/
return 0, nil
}
func (fi *FileInfo) Name() string {
return fi.name
}
func (fi *FileInfo) Size() int64 {
return fi.size
}
func (fi *FileInfo) Mode() os.FileMode {
return fi.mode
}
func (fi *FileInfo) ModTime() time.Time {
return fi.modTime
}
func (fi *FileInfo) IsDir() bool {
return fi.isDir
}
func (fi *FileInfo) Sys() interface{} {
return fi.sys
}