forked from bmaupin/go-epub
-
Notifications
You must be signed in to change notification settings - Fork 5
/
fs.go
47 lines (36 loc) · 1017 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
// Package osfs implements the Storage interface for os' filesystems
package osfs
import (
"io/fs"
"os"
"path/filepath"
"github.com/go-shiori/go-epub/internal/storage"
)
type OSFS struct {
rootDir string
fs.FS
}
func NewOSFS(rootDir string) *OSFS {
return &OSFS{
rootDir: rootDir,
FS: os.DirFS(rootDir),
}
}
func (o *OSFS) WriteFile(name string, data []byte, perm fs.FileMode) error {
return os.WriteFile(filepath.Join(o.rootDir, name), data, perm)
}
func (o *OSFS) Mkdir(name string, perm fs.FileMode) error {
return os.Mkdir(filepath.Join(o.rootDir, name), perm)
}
func (o *OSFS) RemoveAll(name string) error {
return os.RemoveAll(filepath.Join(o.rootDir, name))
}
func (o *OSFS) Create(name string) (storage.File, error) {
return os.Create(filepath.Join(o.rootDir, name))
}
func (o *OSFS) Stat(name string) (fs.FileInfo, error) {
return os.Stat(filepath.Join(o.rootDir, name))
}
func (o *OSFS) Open(name string) (fs.File, error) {
return os.Open(filepath.Join(o.rootDir, name))
}