Merge pull request #782 from krishnasrinivas/no-signature-no-sha256

when signature is not available there is no need to compute sha256
This commit is contained in:
Harshavardhana 2015-07-29 11:21:40 -07:00
commit 179c5441c3

View File

@ -19,6 +19,7 @@ package donut
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"hash"
"io" "io"
"path/filepath" "path/filepath"
"sort" "sort"
@ -247,15 +248,23 @@ func (b bucket) WriteObject(objectName string, objectData io.Reader, size int64,
return ObjectMetadata{}, iodine.New(err, nil) return ObjectMetadata{}, iodine.New(err, nil)
} }
sumMD5 := md5.New() sumMD5 := md5.New()
sum256 := sha256.New()
sum512 := sha512.New() sum512 := sha512.New()
var sum256 hash.Hash
var mwriter io.Writer
if signature != nil {
sum256 = sha256.New()
mwriter = io.MultiWriter(sumMD5, sum256, sum512)
} else {
mwriter = io.MultiWriter(sumMD5, sum512)
}
objMetadata := ObjectMetadata{} objMetadata := ObjectMetadata{}
objMetadata.Version = objectMetadataVersion objMetadata.Version = objectMetadataVersion
objMetadata.Created = time.Now().UTC() objMetadata.Created = time.Now().UTC()
// if total writers are only '1' do not compute erasure // if total writers are only '1' do not compute erasure
switch len(writers) == 1 { switch len(writers) == 1 {
case true: case true:
mw := io.MultiWriter(writers[0], sumMD5, sum256, sum512) mw := io.MultiWriter(writers[0], mwriter)
totalLength, err := io.Copy(mw, objectData) totalLength, err := io.Copy(mw, objectData)
if err != nil { if err != nil {
CleanupWritersOnError(writers) CleanupWritersOnError(writers)
@ -269,7 +278,6 @@ func (b bucket) WriteObject(objectName string, objectData io.Reader, size int64,
CleanupWritersOnError(writers) CleanupWritersOnError(writers)
return ObjectMetadata{}, iodine.New(err, nil) return ObjectMetadata{}, iodine.New(err, nil)
} }
mwriter := io.MultiWriter(sumMD5, sum256, sum512)
// write encoded data with k, m and writers // write encoded data with k, m and writers
chunkCount, totalLength, err := b.writeObjectData(k, m, writers, objectData, size, mwriter) chunkCount, totalLength, err := b.writeObjectData(k, m, writers, objectData, size, mwriter)
if err != nil { if err != nil {