This commit is contained in:
YouROK
2023-01-29 21:31:28 +03:00
parent 50ccd2ed94
commit 96f4bbf8ec
2 changed files with 61 additions and 14 deletions

View File

@@ -1,6 +1,11 @@
package utils
import "strings"
import (
"crypto/sha256"
"encoding/hex"
"os"
"strings"
)
func ClearStr(str string) string {
ret := ""
@@ -12,3 +17,26 @@ func ClearStr(str string) string {
}
return ret
}
func MD5File(fname string) string {
f, err := os.Open(fname)
if err != nil {
return ""
}
defer f.Close()
buf := make([]byte, 1024*1024)
h := sha256.New()
for {
bytesRead, err := f.Read(buf)
if err != nil {
break
}
h.Write(buf[:bytesRead])
}
return hex.EncodeToString(h.Sum(nil))
}