Implemented HelloFS.ReadFile.

geesefs-0-30-9
Aaron Jacobs 2015-02-27 15:57:06 +11:00
parent 4ef670f8b7
commit fe2f872382
1 changed files with 22 additions and 0 deletions

View File

@ -4,7 +4,9 @@
package samples
import (
"io"
"os"
"strings"
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse/fuseutil"
@ -243,3 +245,23 @@ func (fs *HelloFS) OpenFile(
resp = &fuse.OpenFileResponse{}
return
}
func (fs *HelloFS) ReadFile(
ctx context.Context,
req *fuse.ReadFileRequest) (resp *fuse.ReadFileResponse, err error) {
resp = &fuse.ReadFileResponse{}
// Let io.ReaderAt deal with the semantics.
reader := strings.NewReader("Hello, world!")
resp.Data = make([]byte, req.Size)
n, err := reader.ReadAt(resp.Data, req.Offset)
resp.Data = resp.Data[:n]
// Special case: FUSE doesn't expect us to return io.EOF.
if err == io.EOF {
err = nil
}
return
}