torrent/fs/filenode.go

31 lines
533 B
Go
Raw Normal View History

package torrentfs
import (
2018-01-31 05:42:26 +00:00
"context"
"bazil.org/fuse"
fusefs "bazil.org/fuse/fs"
2019-08-21 10:58:40 +00:00
2018-01-09 12:12:01 +00:00
"github.com/anacrolix/torrent"
)
type fileNode struct {
node
2018-01-06 05:37:13 +00:00
f *torrent.File
}
var (
_ fusefs.NodeOpener = fileNode{}
)
func (fn fileNode) Attr(ctx context.Context, attr *fuse.Attr) error {
2018-01-06 05:37:13 +00: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 05:37:13 +00:00
r := fn.f.NewReader()
return fileHandle{fn, r}, nil
}