-
Notifications
You must be signed in to change notification settings - Fork 43
/
file.go
50 lines (38 loc) · 884 Bytes
/
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
package subdirfs
import (
"io"
"path/filepath"
"gopkg.in/src-d/go-billy.v2"
)
type file struct {
billy.BaseFile
f billy.File
}
func newFile(fs billy.Filesystem, f billy.File, filename string) billy.File {
filename = fs.Join(fs.Base(), filename)
filename, _ = filepath.Rel(fs.Base(), filename)
return &file{
BaseFile: billy.BaseFile{BaseFilename: filename},
f: f,
}
}
func (f *file) Read(p []byte) (int, error) {
return f.f.Read(p)
}
func (f *file) ReadAt(b []byte, off int64) (int, error) {
rf, ok := f.f.(io.ReaderAt)
if !ok {
return 0, billy.ErrNotSupported
}
return rf.ReadAt(b, off)
}
func (f *file) Seek(offset int64, whence int) (int64, error) {
return f.f.Seek(offset, whence)
}
func (f *file) Write(p []byte) (int, error) {
return f.f.Write(p)
}
func (f *file) Close() error {
defer func() { f.Closed = true }()
return f.f.Close()
}