|
|
|
@ -2,6 +2,7 @@ package util |
|
|
|
|
|
|
|
import ( |
|
|
|
"archive/zip" |
|
|
|
"crypto/sha256" |
|
|
|
"encoding/base64" |
|
|
|
"fmt" |
|
|
|
"fssc/config" |
|
|
|
@ -250,3 +251,32 @@ func Base64dec(bsstr string) string { |
|
|
|
dedc, _ := base64.URLEncoding.DecodeString(bsstr) |
|
|
|
return string(dedc) |
|
|
|
} |
|
|
|
|
|
|
|
// 计算文件的hash
|
|
|
|
func CalacHash(rfile string, relpath string) string { |
|
|
|
// 获取到真实地址
|
|
|
|
rpath := filepath.Join(config.G.FilePath, rfile) |
|
|
|
// fmt.Printf("hash file calac is :%s\n", rpath)
|
|
|
|
// if os.IsNotExist(rpath) {
|
|
|
|
// return "0x00"
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
file, err := os.Open(rpath) |
|
|
|
if err != nil { |
|
|
|
panic(err) |
|
|
|
} |
|
|
|
defer file.Close() |
|
|
|
|
|
|
|
// initlize hash object
|
|
|
|
hash := sha256.New() |
|
|
|
|
|
|
|
// write file into hash object
|
|
|
|
if _, err := io.Copy(hash, file); err != nil { |
|
|
|
panic(err) |
|
|
|
} |
|
|
|
// get hash value
|
|
|
|
hashBytes := hash.Sum(nil) |
|
|
|
//converto to hash string
|
|
|
|
hastString := fmt.Sprintf("%x", hashBytes) |
|
|
|
return hastString |
|
|
|
} |
|
|
|
|