Skip to content

Commit

Permalink
check file sha256sum by streaming to save memory usage. good for mach…
Browse files Browse the repository at this point in the history
…ine with limited memory size.
  • Loading branch information
samt42 committed Nov 3, 2023
1 parent f6211b5 commit 668ae5f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/kk/pkg/files/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 668ae5f

Please sign in to comment.