-
Notifications
You must be signed in to change notification settings - Fork 238
/
fs.go
49 lines (40 loc) · 870 Bytes
/
fs.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
package main
import (
"io"
"io/ioutil"
"os"
)
// FileSystem ...
type FileSystem interface {
Exists(path string) bool
MkdirP(path string) error
Create(name string) (File, error)
WriteFile(path string, content []byte) error
}
// File ...
type File interface {
io.Closer
io.Reader
io.ReaderAt
io.Seeker
io.Writer
Stat() (os.FileInfo, error)
}
var fs = &osFileSystem{}
type osFileSystem struct{}
func (*osFileSystem) Exists(path string) bool {
_, err := os.Stat(path)
return err == nil
}
func (*osFileSystem) MkdirP(path string) error {
if _, err := os.Stat(path); os.IsNotExist(err) {
return os.MkdirAll(path, os.ModePerm)
}
return nil
}
func (*osFileSystem) Create(name string) (File, error) {
return os.Create(name)
}
func (*osFileSystem) WriteFile(path string, content []byte) error {
return ioutil.WriteFile(path, content, os.ModePerm)
}