-
Notifications
You must be signed in to change notification settings - Fork 1
/
webfs.go
62 lines (48 loc) · 1 KB
/
webfs.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
58
59
60
61
62
package extractor
import (
"fmt"
"io"
"io/fs"
)
const cdnTemplate = "https://patchcdn.pathofexile.com/%s/"
var _ fs.FS = (*WebFS)(nil)
type WebFS struct {
BasePath string
}
func NewWebFS(gameVersion string) *WebFS {
return &WebFS{
BasePath: fmt.Sprintf(cdnTemplate, gameVersion),
}
}
func (w *WebFS) Open(name string) (fs.File, error) {
return &WebFile{
BasePath: w.BasePath,
Name: name,
}, nil
}
var _ io.ReaderAt = (*WebFile)(nil)
type WebFile struct {
BasePath string
Name string
CachedFile []byte
}
func (w *WebFile) ReadAt(p []byte, off int64) (int, error) {
if _, err := w.Read([]byte{}); err != nil {
return 0, err
}
return copy(p, w.CachedFile[off:]), nil
}
func (w *WebFile) Stat() (fs.FileInfo, error) {
// Do nothing
return nil, nil
}
func (w *WebFile) Read(bytes []byte) (int, error) {
if w.CachedFile == nil {
w.CachedFile = Fetch(w.BasePath + w.Name)
}
return copy(bytes, w.CachedFile), nil
}
func (w *WebFile) Close() error {
// Do nothing
return nil
}