aboutsummaryrefslogtreecommitdiff
path: root/weed/util/bytes.go
diff options
context:
space:
mode:
authorhasagi <30975629+LIBA-S@users.noreply.github.com>2020-09-22 21:38:38 +0800
committerGitHub <noreply@github.com>2020-09-22 21:38:38 +0800
commitd7bf2390e2bf4ac55132878faa68119b3558e8e4 (patch)
tree48ede45893c2130d3e039f7fe4af8440835eb02d /weed/util/bytes.go
parent37e964d4bd60a9dd792a9cc24f05eaa05d3766f2 (diff)
parentec5b9f1e91a8609d0e70bf9d26dc0840774153c4 (diff)
downloadseaweedfs-d7bf2390e2bf4ac55132878faa68119b3558e8e4.tar.xz
seaweedfs-d7bf2390e2bf4ac55132878faa68119b3558e8e4.zip
Merge pull request #1 from chrislusf/master
catch up
Diffstat (limited to 'weed/util/bytes.go')
-rw-r--r--weed/util/bytes.go32
1 files changed, 30 insertions, 2 deletions
diff --git a/weed/util/bytes.go b/weed/util/bytes.go
index 0650919c0..82e4ddeef 100644
--- a/weed/util/bytes.go
+++ b/weed/util/bytes.go
@@ -2,6 +2,8 @@ package util
import (
"crypto/md5"
+ "crypto/rand"
+ "encoding/base64"
"fmt"
"io"
)
@@ -109,8 +111,34 @@ 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 {
+ return Base64Encode(Md5(data))
+}
+
+func Md5(data []byte) []byte {
hash := md5.New()
hash.Write(data)
- return fmt.Sprintf("%x", hash.Sum(nil))
+ return hash.Sum(nil)
+}
+
+func Md5String(data []byte) string {
+ return fmt.Sprintf("%x", Md5(data))
+}
+
+func Base64Md5ToBytes(contentMd5 string) []byte {
+ data, err := base64.StdEncoding.DecodeString(contentMd5)
+ if err != nil {
+ return nil
+ }
+ return data
+}
+
+func RandomInt32() int32 {
+ buf := make([]byte, 4)
+ rand.Read(buf)
+ return int32(BytesToUint32(buf))
}