-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsqlite3vfshttp.go
97 lines (75 loc) · 2.03 KB
/
sqlite3vfshttp.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package sqlite3vfshttp
import (
"errors"
"net/http"
"strings"
"github.com/psanford/httpreadat"
"github.com/psanford/sqlite3vfs"
)
type HttpVFS struct {
URL string
CacheHandler httpreadat.CacheHandler
RoundTripper http.RoundTripper
}
func (vfs *HttpVFS) Open(name string, flags sqlite3vfs.OpenFlag) (sqlite3vfs.File, sqlite3vfs.OpenFlag, error) {
var opts []httpreadat.Option
if vfs.CacheHandler != nil {
opts = append(opts, httpreadat.WithCacheHandler(vfs.CacheHandler))
}
if vfs.RoundTripper != nil {
opts = append(opts, httpreadat.WithRoundTripper(vfs.RoundTripper))
}
tf := &httpFile{
rr: httpreadat.New(vfs.URL, opts...),
}
return tf, flags, nil
}
func (vfs *HttpVFS) Delete(name string, dirSync bool) error {
return sqlite3vfs.ReadOnlyError
}
func (vfs *HttpVFS) Access(name string, flag sqlite3vfs.AccessFlag) (bool, error) {
if strings.HasSuffix(name, "-wal") || strings.HasSuffix(name, "-journal") {
return false, nil
}
return true, nil
}
func (vfs *HttpVFS) FullPathname(name string) string {
return name
}
type httpFile struct {
rr *httpreadat.RangeReader
}
func (tf *httpFile) Close() error {
return nil
}
func (tf *httpFile) ReadAt(p []byte, off int64) (int, error) {
return tf.rr.ReadAt(p, off)
}
func (tf *httpFile) WriteAt(b []byte, off int64) (n int, err error) {
return 0, sqlite3vfs.ReadOnlyError
}
func (tf *httpFile) Truncate(size int64) error {
return sqlite3vfs.ReadOnlyError
}
func (tf *httpFile) Sync(flag sqlite3vfs.SyncType) error {
return nil
}
var invalidContentRangeErr = errors.New("invalid Content-Range response")
func (tf *httpFile) FileSize() (int64, error) {
return tf.rr.Size()
}
func (tf *httpFile) Lock(elock sqlite3vfs.LockType) error {
return nil
}
func (tf *httpFile) Unlock(elock sqlite3vfs.LockType) error {
return nil
}
func (tf *httpFile) CheckReservedLock() (bool, error) {
return false, nil
}
func (tf *httpFile) SectorSize() int64 {
return 0
}
func (tf *httpFile) DeviceCharacteristics() sqlite3vfs.DeviceCharacteristic {
return sqlite3vfs.IocapImmutable
}