-
Notifications
You must be signed in to change notification settings - Fork 1
/
file.go
43 lines (35 loc) · 862 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
package aferofuse
import (
"errors"
"io"
"github.com/hanwen/go-fuse/v2/fuse"
"github.com/hanwen/go-fuse/v2/fuse/nodefs"
"github.com/spf13/afero"
)
type aferoFuseFile struct {
nodefs.File
file afero.File
}
func (f *aferoFuseFile) Read(dest []byte, off int64) (fuse.ReadResult, fuse.Status) {
_, err := f.file.ReadAt(dest, off)
if errors.Is(err, io.EOF) {
err = nil
}
if err != nil {
return nil, fuse.ToStatus(err)
}
return fuse.ReadResultData(dest), fuse.ToStatus(nil)
}
func (f *aferoFuseFile) Write(dest []byte, off int64) (uint32, fuse.Status) {
n, err := f.file.WriteAt(dest, off)
if errors.Is(err, io.EOF) {
err = nil
}
return uint32(n), fuse.ToStatus(err)
}
func (f *aferoFuseFile) Release() {
f.file.Close()
}
func (f *aferoFuseFile) Truncate(size uint64) fuse.Status {
return fuse.ToStatus(f.file.Truncate(int64(size)))
}