check file sha256sum by streaming to save memory usage. good for machine with limited memory size.

This commit is contained in:
samt42 2023-11-03 12:36:32 +08:00
parent f6211b5f76
commit 668ae5f099

View File

@ -320,9 +320,9 @@ func sha256sum(path string) (string, error) {
}
defer file.Close()
data, err := io.ReadAll(file)
if err != nil {
hasher := sha256.New()
if _, err := io.Copy(hasher, file); err != nil {
return "", err
}
return fmt.Sprintf("%x", sha256.Sum256(data)), nil
return fmt.Sprintf("%x", hasher.Sum(nil)), nil
}