refactor ObjectLayer PutObject and PutObjectPart (#4925)

This change refactor the ObjectLayer PutObject and PutObjectPart
functions. Instead of passing an io.Reader and a size to PUT operations
ObejectLayer expects an HashReader.
A HashReader verifies the MD5 sum (and SHA256 sum if required) of the object.
This change updates all all PutObject(Part) calls and removes unnecessary code
in all ObjectLayer implementations.

Fixes #4923
This commit is contained in:
Andreas Auernhammer
2017-09-19 12:40:27 -07:00
committed by Dee Koder
parent f8024cadbb
commit 79ba4d3f33
38 changed files with 310 additions and 663 deletions

View File

@@ -19,7 +19,6 @@ package cmd
import (
"encoding/hex"
"fmt"
"io"
"path"
"runtime"
"strings"
@@ -269,27 +268,3 @@ type byBucketName []BucketInfo
func (d byBucketName) Len() int { return len(d) }
func (d byBucketName) Swap(i, j int) { d[i], d[j] = d[j], d[i] }
func (d byBucketName) Less(i, j int) bool { return d[i].Name < d[j].Name }
// rangeReader returns a Reader that reads from r
// but returns error after Max bytes read as errDataTooLarge.
// but returns error if reader exits before reading Min bytes
// errDataTooSmall.
type rangeReader struct {
Reader io.Reader // underlying reader
Min int64 // min bytes remaining
Max int64 // max bytes remaining
}
func (l *rangeReader) Read(p []byte) (n int, err error) {
n, err = l.Reader.Read(p)
l.Max -= int64(n)
l.Min -= int64(n)
if l.Max < 0 {
// If more data is available than what is expected we return error.
return 0, errDataTooLarge
}
if err == io.EOF && l.Min > 0 {
return 0, errDataTooSmall
}
return
}