-
Notifications
You must be signed in to change notification settings - Fork 1
/
file.go
67 lines (50 loc) · 1.27 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package sqlitezstd
import (
"io"
seekable "github.com/SaveTheRbtz/zstd-seekable-format-go/pkg"
"github.com/klauspost/compress/zstd"
"github.com/psanford/sqlite3vfs"
)
type ZstdFile struct {
decoder *zstd.Decoder
reader io.ReadSeeker
seekable seekable.Reader
}
var _ sqlite3vfs.File = &ZstdFile{}
func (z *ZstdFile) CheckReservedLock() (bool, error) {
return false, nil
}
func (z *ZstdFile) Close() error {
_ = z.seekable.Close()
if closer, ok := z.reader.(io.Closer); ok {
_ = closer.Close()
}
return nil
}
func (z *ZstdFile) DeviceCharacteristics() sqlite3vfs.DeviceCharacteristic {
return sqlite3vfs.IocapImmutable
}
func (z *ZstdFile) FileSize() (int64, error) {
return z.seekable.Seek(0, io.SeekEnd)
}
func (z *ZstdFile) Lock(elock sqlite3vfs.LockType) error {
return nil
}
func (z *ZstdFile) ReadAt(p []byte, off int64) (int, error) {
return z.seekable.ReadAt(p, off)
}
func (z *ZstdFile) SectorSize() int64 {
return 0
}
func (z *ZstdFile) Sync(flag sqlite3vfs.SyncType) error {
return nil
}
func (z *ZstdFile) Truncate(size int64) error {
return sqlite3vfs.ReadOnlyError
}
func (z *ZstdFile) Unlock(elock sqlite3vfs.LockType) error {
return nil
}
func (z *ZstdFile) WriteAt(p []byte, off int64) (int, error) {
return 0, sqlite3vfs.ReadOnlyError
}