github.com/anacrolix/torrent@v1.61.0/fs/filenode.go (about)

     1  //go:build !windows
     2  
     3  package torrentfs
     4  
     5  import (
     6  	"context"
     7  
     8  	"github.com/anacrolix/fuse"
     9  	fusefs "github.com/anacrolix/fuse/fs"
    10  
    11  	"github.com/anacrolix/torrent"
    12  )
    13  
    14  type fileNode struct {
    15  	node
    16  	f *torrent.File
    17  }
    18  
    19  var _ fusefs.NodeOpener = fileNode{}
    20  
    21  func (fn fileNode) Attr(ctx context.Context, attr *fuse.Attr) error {
    22  	attr.Size = uint64(fn.f.Length())
    23  	attr.Mode = defaultMode
    24  	return nil
    25  }
    26  
    27  func (fn fileNode) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fusefs.Handle, error) {
    28  	return fileHandle{fn, fn.f}, nil
    29  }