add zip and parity stuff

This commit is contained in:
2023-07-18 18:21:12 -06:00
parent 8abb1408f0
commit f260ee1c9f
11 changed files with 403 additions and 21 deletions

View File

@ -1,11 +1,10 @@
package source
import (
"crypto/sha256"
"fmt"
"forever-files/db"
"forever-files/fileUtilities"
"forever-files/types"
"io"
"log"
"os"
"path"
@ -46,13 +45,13 @@ func walkDir(dirPath string, db db.DB) error {
log.Default().Printf("error getting file info: %v", err)
continue
}
hash, err := hashFile(path.Join(dirPath, entry.Name()))
hash, err := fileUtilities.HashFile(path.Join(dirPath, entry.Name()))
if err != nil {
log.Default().Printf("error hashing file: %v", err)
continue
}
// store info
fmt.Printf("Name: %v, Size: %v, Modified Date: %v, Hash: %v\n", fileInfo.Name(), fileInfo.Size(), fileInfo.ModTime(), hash)
//fmt.Printf("Name: %v, Size: %v, Modified Date: %v, Hash: %v\n", fileInfo.Name(), fileInfo.Size(), fileInfo.ModTime(), hash)
err = db.StoreFile(types.FileMetadata{
Name: fileInfo.Name(),
Path: dirPath,
@ -69,18 +68,3 @@ func walkDir(dirPath string, db db.DB) error {
}
return nil
}
func hashFile(filePath string) ([]byte, error) {
file, err := os.Open(filePath)
if err != nil {
return []byte{}, fmt.Errorf("error opening file for hashing: %w", err)
}
defer file.Close()
h := sha256.New()
if _, err := io.Copy(h, file); err != nil {
return []byte{}, fmt.Errorf("error hashing file: %w", err)
}
return h.Sum(nil), nil
}