2017-08-26 11:25:04 +08:00
|
|
|
package torrentfs
|
|
|
|
|
|
|
|
import (
|
2018-01-31 13:42:26 +08:00
|
|
|
"context"
|
|
|
|
|
2017-08-26 11:25:04 +08:00
|
|
|
"bazil.org/fuse"
|
|
|
|
fusefs "bazil.org/fuse/fs"
|
2018-01-09 20:12:01 +08:00
|
|
|
|
|
|
|
"github.com/anacrolix/torrent"
|
2017-08-26 11:25:04 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type fileNode struct {
|
|
|
|
node
|
2018-01-06 13:37:13 +08:00
|
|
|
f *torrent.File
|
2017-08-26 11:25:04 +08:00
|
|
|
}
|
|
|
|
|
2017-08-27 12:19:58 +08:00
|
|
|
var (
|
|
|
|
_ fusefs.NodeOpener = fileNode{}
|
|
|
|
)
|
2017-08-26 11:25:04 +08:00
|
|
|
|
|
|
|
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())
|
2017-08-26 11:25:04 +08:00
|
|
|
attr.Mode = defaultMode
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-08-27 12:19:58 +08:00
|
|
|
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()
|
2017-08-27 23:42:02 +08:00
|
|
|
return fileHandle{fn, r}, nil
|
2017-08-26 11:25:04 +08:00
|
|
|
}
|