Ajout récupération de fichier (fingerprint à check)

This commit is contained in:
2022-03-15 11:58:06 +01:00
parent 7db026f710
commit 8a61165428
8 changed files with 183 additions and 12 deletions

View File

@@ -8,9 +8,9 @@ import (
)
// SendFile Envoie d'un fichier local sur le réseau
func SendFile(fileName string, fileSize int, writer *bufio.Writer) bool {
func SendFile(filePath string, fileSize int, writer *bufio.Writer) bool {
// Ouverture du fichier
file, fileErr := os.Open(fmt.Sprintf("/home/benjamin/sbe/%s", fileName))
file, fileErr := os.Open(fmt.Sprintf("%s", filePath))
if fileErr != nil {
return false
}
@@ -25,5 +25,5 @@ func SendFile(fileName string, fileSize int, writer *bufio.Writer) bool {
return false
}
return false
return true
}

View File

@@ -10,6 +10,12 @@ import (
)
func HashFileCompare(path string, fingerPrint string) bool {
sum := GenFingerPrint(path)
return fingerPrint == fmt.Sprintf("%x", sum)
}
func GenFingerPrint(path string) []byte {
f, err := os.Open(path)
if err != nil {
log.Fatal(err)
@@ -24,8 +30,5 @@ func HashFileCompare(path string, fingerPrint string) bool {
}
sum := hash.Sum(nil)
fmt.Printf("%x\n", sum)
println(fingerPrint, fmt.Sprintf("%x", sum))
return fingerPrint == fmt.Sprintf("%x", sum)
return sum
}