forked from gobuffalo/packr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtual_file.go
57 lines (47 loc) · 974 Bytes
/
virtual_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
package packr
import (
"bytes"
"fmt"
"os"
"time"
)
var virtualFileModTime = time.Now()
var _ File = virtualFile{}
type virtualFile struct {
*bytes.Reader
Name string
info fileInfo
}
func (f virtualFile) FileInfo() (os.FileInfo, error) {
return f.info, nil
}
func (f virtualFile) Close() error {
return nil
}
func (f virtualFile) Write(p []byte) (n int, err error) {
return 0, fmt.Errorf("not implemented")
}
func (f virtualFile) Readdir(count int) ([]os.FileInfo, error) {
return []os.FileInfo{f.info}, nil
}
func (f virtualFile) Stat() (os.FileInfo, error) {
return f.info, nil
}
func newVirtualFile(name string, b []byte) File {
return virtualFile{
Reader: bytes.NewReader(b),
Name: name,
info: fileInfo{
Path: name,
Contents: b,
size: int64(len(b)),
modTime: virtualFileModTime,
},
}
}
func newVirtualDir(name string) File {
var b []byte
v := newVirtualFile(name, b).(virtualFile)
v.info.isDir = true
return v
}