FedP2P/fs/filenode.go

29 lines
550 B
Go
Raw Normal View History

package torrentfs
import (
2018-01-31 13:42:26 +08:00
"context"
2021-11-16 15:20:02 +08:00
"github.com/anacrolix/fuse"
fusefs "github.com/anacrolix/fuse/fs"
2019-08-21 18:58:40 +08:00
2018-01-09 20:12:01 +08:00
"github.com/anacrolix/torrent"
)
type fileNode struct {
node
2018-01-06 13:37:13 +08:00
f *torrent.File
}
2021-11-08 11:47:01 +08:00
var _ fusefs.NodeOpener = fileNode{}
func (fn fileNode) Attr(ctx context.Context, attr *fuse.Attr) error {
2018-01-06 13:37:13 +08:00
attr.Size = uint64(fn.f.Length())
attr.Mode = defaultMode
return nil
}
func (fn fileNode) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fusefs.Handle, error) {
2018-01-06 13:37:13 +08:00
r := fn.f.NewReader()
return fileHandle{fn, r}, nil
}