Files
TorrServerJellyfin/server/rutor/utils/utils.go
2023-01-29 21:31:28 +03:00

43 lines
628 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils
import (
"crypto/sha256"
"encoding/hex"
"os"
"strings"
)
func ClearStr(str string) string {
ret := ""
str = strings.ToLower(str)
for _, r := range str {
if (r >= '0' && r <= '9') || (r >= 'a' && r <= 'z') || (r >= 'а' && r <= 'я') || r == 'ё' {
ret = ret + string(r)
}
}
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))
}