From b51e6b0485a751ac2b38159b6f82f272c911c43d Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 21 Nov 2016 02:53:24 -0800 Subject: [PATCH] Fix downloading files with exact ranges requested in client FS. (#1892) This is due to the fact that ReadAt() will not send io.EOF when reading past the offset, server instead returns Range error. Handle the error by only reading until the requested size. --- cmd/client-fs.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/client-fs.go b/cmd/client-fs.go index 82746113..c73ef857 100644 --- a/cmd/client-fs.go +++ b/cmd/client-fs.go @@ -246,12 +246,13 @@ func (f *fsClient) Put(reader io.Reader, size int64, contentType string, progres return 0, probe.NewError(e) } } + // Allocate buffer of 10MiB once. readAtBuffer := make([]byte, 10*1024*1024) // Loop through all offsets on incoming io.ReaderAt and write // to the destination. - for { + for currentOffset < size { readAtSize, re := readerAt.ReadAt(readAtBuffer, currentOffset) if re != nil && re != io.EOF { // For any errors other than io.EOF, we return error