From 2895b0accaad4465128e4b950bf048494de36a9f Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Wed, 9 Nov 2016 01:59:23 +0100 Subject: [PATCH] Put() in client fs avoids reading from input reader when data is zero lengthy (#1879) --- cmd/client-fs.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/client-fs.go b/cmd/client-fs.go index e7cba5fa..174316e2 100644 --- a/cmd/client-fs.go +++ b/cmd/client-fs.go @@ -241,8 +241,10 @@ func (f *fsClient) Put(reader io.Reader, size int64, contentType string, progres // Current file offset. var currentOffset = partSt.Size() - // Verify if incoming reader implements ReaderAt. Standard IO streams are excluded since their ReadAt() return illegal seek error - if readerAt, ok := reader.(io.ReaderAt); ok && !isStdIO(reader) { + // Use ReadAt() capability when reader implements it, but also avoid it in two cases: + // *) reader represents a standard input/output stream since they return illegal seek error when ReadAt() is invoked + // *) we know in advance that reader will provide zero length data + if readerAt, ok := reader.(io.ReaderAt); ok && !isStdIO(reader) && size > 0 { // Notify the progress bar if any till current size. if progress != nil { if _, e = io.CopyN(ioutil.Discard, progress, currentOffset); e != nil {