filer: store md5 metadata for files uploaded by filer

fix https://github.com/chrislusf/seaweedfs/issues/1412
This commit is contained in:
Chris Lu
2020-08-06 10:04:17 -07:00
parent 93ea0801ea
commit 20e2ac1add
7 changed files with 41 additions and 38 deletions

View File

@@ -2,6 +2,7 @@ package util
import (
"crypto/md5"
"encoding/base64"
"fmt"
"io"
)
@@ -109,8 +110,20 @@ func HashToInt32(data []byte) (v int32) {
return
}
func Md5(data []byte) string {
func Base64Encode(data []byte) string {
return base64.StdEncoding.EncodeToString(data)
}
func Base64Md5(data []byte) string {
hash := md5.New()
hash.Write(data)
return fmt.Sprintf("%x", hash.Sum(nil))
return Base64Encode(hash.Sum(nil))
}
func Base64Md5ToBytes(contentMd5 string) []byte {
data, err := base64.StdEncoding.DecodeString(contentMd5)
if err != nil {
return nil
}
return data
}