mirror of
https://github.com/minio/minio.git
synced 2025-11-07 21:02:58 -05:00
Provide ETag with sha256Sum of input object data
This commit is contained in:
@@ -18,10 +18,13 @@ package storage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"crypto/sha256"
|
||||
)
|
||||
|
||||
type Storage struct {
|
||||
@@ -49,6 +52,7 @@ type ObjectMetadata struct {
|
||||
Key string
|
||||
SecCreated int64
|
||||
Size int
|
||||
ETag string
|
||||
}
|
||||
|
||||
func isValidBucket(bucket string) bool {
|
||||
@@ -108,10 +112,13 @@ func (storage *Storage) StoreObject(bucket string, key string, data io.Reader) e
|
||||
var bytesBuffer bytes.Buffer
|
||||
newObject := storedObject{}
|
||||
if _, ok := io.Copy(&bytesBuffer, data); ok == nil {
|
||||
size := bytesBuffer.Len()
|
||||
etag := fmt.Sprintf("%x", sha256.Sum256(bytesBuffer.Bytes()))
|
||||
newObject.metadata = ObjectMetadata{
|
||||
Key: key,
|
||||
SecCreated: time.Now().Unix(),
|
||||
Size: len(bytesBuffer.Bytes()),
|
||||
Size: size,
|
||||
ETag: etag,
|
||||
}
|
||||
newObject.data = bytesBuffer.Bytes()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user