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