From 9dced9a8903fb45b38f40a3ae1e2cf56ceb2024b Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Wed, 13 Jan 2016 12:43:13 -0800 Subject: [PATCH] alex: making the readat more efficient --- client/allocdir/alloc_dir.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/client/allocdir/alloc_dir.go b/client/allocdir/alloc_dir.go index ea5a3d441..03cd0ecb5 100644 --- a/client/allocdir/alloc_dir.go +++ b/client/allocdir/alloc_dir.go @@ -255,15 +255,13 @@ func (d *AllocDir) FSStat(path string) (*AllocFile, error) { } func (d *AllocDir) FSReadAt(allocID string, path string, offset int64, limit int64, w io.Writer) error { - buf := make([]byte, limit) p := filepath.Join(d.AllocDir, path) f, err := os.Open(p) if err != nil { return err } - n, err := f.ReadAt(buf, offset) - w.Write(buf[:n]) - return err + io.Copy(w, io.LimitReader(f, limit)) + return nil } func fileCopy(src, dst string, perm os.FileMode) error {