-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfile.go
51 lines (40 loc) · 883 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
51
package gitfs
import (
"io"
"io/fs"
"github.com/go-git/go-billy/v5"
)
type GitFile struct {
file billy.File
path string
fs *GitFS
dirOffset int
}
func (g *GitFile) Read(bytes []byte) (int, error) {
return g.file.Read(bytes)
}
func (g *GitFile) Close() error {
return g.file.Close()
}
func (g *GitFile) Stat() (fs.FileInfo, error) {
return g.fs.Stat(g.path)
}
func (g *GitFile) ReadDir(n int) ([]fs.DirEntry, error) {
entries, err := g.fs.ReadDir(g.path)
// directory already exhausted
if n <= 0 && g.dirOffset >= len(entries) {
return nil, nil
}
// read till end
if n > 0 && g.dirOffset+n > len(entries) {
err = io.EOF
}
if n > 0 && g.dirOffset+n <= len(entries) {
entries = entries[g.dirOffset : g.dirOffset+n]
g.dirOffset += n
} else {
entries = entries[g.dirOffset:]
g.dirOffset += len(entries)
}
return entries, err
}