fuseutil.go 540 B

123456789101112131415161718192021
  1. package fuseutil // import "bazil.org/fuse/fuseutil"
  2. import (
  3. "bazil.org/fuse"
  4. )
  5. // HandleRead handles a read request assuming that data is the entire file content.
  6. // It adjusts the amount returned in resp according to req.Offset and req.Size.
  7. func HandleRead(req *fuse.ReadRequest, resp *fuse.ReadResponse, data []byte) {
  8. if req.Offset >= int64(len(data)) {
  9. data = nil
  10. } else {
  11. data = data[req.Offset:]
  12. }
  13. if len(data) > req.Size {
  14. data = data[:req.Size]
  15. }
  16. n := copy(resp.Data[:req.Size], data)
  17. resp.Data = resp.Data[:n]
  18. }