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
|
package scl
import (
"io"
"os"
"path/filepath"
"strings"
"time"
)
type diskFileSystem struct {
basePath string
}
/*
NewDiskSystem creates a filesystem that uses the local disk, at an optional
base path. The default base path is the current working directory.
*/
func NewDiskSystem(basePath ...string) FileSystem {
base := ""
if len(basePath) > 0 {
base = basePath[0]
}
return &diskFileSystem{base}
}
func (d *diskFileSystem) path(path string) string {
return filepath.Join(d.basePath, strings.TrimPrefix(path, d.basePath))
}
func (d *diskFileSystem) Glob(pattern string) (out []string, err error) {
return filepath.Glob(d.path(pattern))
}
func (d *diskFileSystem) ReadCloser(path string) (data io.ReadCloser, lastModified time.Time, err error) {
reader, err := os.Open(d.path(path))
if err != nil {
return nil, time.Time{}, err
}
stat, err := reader.Stat()
if err != nil {
return nil, time.Time{}, err
}
return reader, stat.ModTime(), nil
}
|