Adding Read method to file

This commit is contained in:
Alex Yatskov 2015-05-24 15:16:12 +09:00
parent c156800411
commit 190098a285

18
file.go
View File

@ -26,6 +26,7 @@ import (
"bazil.org/fuse" "bazil.org/fuse"
"golang.org/x/net/context" "golang.org/x/net/context"
"io/ioutil" "io/ioutil"
"log"
"os" "os"
) )
@ -78,9 +79,20 @@ func (this versionedFile) Fsync(ctx context.Context, req *fuse.FsyncRequest) err
return nil return nil
} }
// func (this versionedFile) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { func (this versionedFile) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
// return nil file, err := os.OpenFile(this.node.rebasedPath(), os.O_RDONLY, 0666)
// } if err != nil {
return err
}
defer file.Close()
resp.Data = make([]byte, req.Size, req.Size)
if _, err = file.ReadAt(resp.Data, req.Offset); err != nil {
return err
}
return nil
}
func (this versionedFile) ReadAll(ctx context.Context) ([]byte, error) { func (this versionedFile) ReadAll(ctx context.Context) ([]byte, error) {
bytes, err := ioutil.ReadFile(this.node.rebasedPath()) bytes, err := ioutil.ReadFile(this.node.rebasedPath())