2017-08-26 11:25:04 +08:00
|
|
|
package torrentfs
|
|
|
|
|
|
|
|
import (
|
2017-11-07 21:12:34 +08:00
|
|
|
"io"
|
2017-08-27 23:42:02 +08:00
|
|
|
|
2017-08-26 11:25:04 +08:00
|
|
|
"bazil.org/fuse"
|
|
|
|
fusefs "bazil.org/fuse/fs"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
type fileNode struct {
|
|
|
|
node
|
|
|
|
size uint64
|
|
|
|
TorrentOffset int64
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
attr.Size = fn.size
|
|
|
|
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) {
|
2017-08-27 23:42:02 +08:00
|
|
|
r := fn.t.NewReader()
|
2017-11-07 21:12:34 +08:00
|
|
|
r.Seek(fn.TorrentOffset, io.SeekStart)
|
2017-08-27 23:42:02 +08:00
|
|
|
return fileHandle{fn, r}, nil
|
2017-08-26 11:25:04 +08:00
|
|
|
}
|