Add field FileSHA in BasicDigest struct
This commit is contained in:
parent
65e8cecbac
commit
98a95282f9
4 changed files with 31 additions and 19 deletions
19
core/pkg/file/file.go
Normal file
19
core/pkg/file/file.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package file
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// SHA1 returns the SHA1 of a file.
|
||||
func SHA1(filename string) string {
|
||||
hasher := sha1.New()
|
||||
s, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
hasher.Write(s)
|
||||
return hex.EncodeToString(hasher.Sum(nil))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue