aboutsummaryrefslogtreecommitdiff
path: root/weed/util/bytes.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-08-06 10:04:17 -0700
committerChris Lu <chris.lu@gmail.com>2020-08-06 10:04:17 -0700
commit20e2ac1add0e93710d54f41c8ba142918c60d620 (patch)
tree4fadb3236551f8aab1037bc6f6ec5351f169fcea /weed/util/bytes.go
parent93ea0801ea65375c16f148c9e77056e6c145f770 (diff)
downloadseaweedfs-20e2ac1add0e93710d54f41c8ba142918c60d620.tar.xz
seaweedfs-20e2ac1add0e93710d54f41c8ba142918c60d620.zip
filer: store md5 metadata for files uploaded by filer
fix https://github.com/chrislusf/seaweedfs/issues/1412
Diffstat (limited to 'weed/util/bytes.go')
-rw-r--r--weed/util/bytes.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/weed/util/bytes.go b/weed/util/bytes.go
index 0650919c0..5076c3e67 100644
--- a/weed/util/bytes.go
+++ b/weed/util/bytes.go
@@ -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
}