mirror of
https://github.com/JaCoB1123/dupe-finder.git
synced 2025-12-13 06:32:34 +01:00
Extract filesmap to own file
This commit is contained in:
18
file.go
18
file.go
@@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -37,3 +40,18 @@ func moveButDontOvewrite(path string, targetPath string) {
|
||||
num++
|
||||
}
|
||||
}
|
||||
|
||||
func calculateHash(path string) (string, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
h := sha256.New()
|
||||
if _, err := io.Copy(h, f); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return base64.RawStdEncoding.EncodeToString(h.Sum(nil)), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user