mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
- Extract shared applyDetailScroll into tui_helpers.go (was duplicated across diff_tui.go, log_tui.go, audit_tui.go) - Create utils.FileHash and utils.FileHashFormatted, replacing private copies in install/meta.go and audit/audit.go - Export install.MetaFileName constant, use from diff_file.go - Replace double SHA-256 in fileContentsEqual with streaming byte compare for early-exit efficiency - Add 1MB size cap to generateUnifiedDiff to prevent performance issues - Move noTUI into diffRenderOpts struct, simplifying function signatures
33 lines
617 B
Go
33 lines
617 B
Go
package utils
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
// FileHash returns the hex-encoded SHA-256 digest of a file.
|
|
func FileHash(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 hex.EncodeToString(h.Sum(nil)), nil
|
|
}
|
|
|
|
// FileHashFormatted returns the hash in "sha256:<hex>" format.
|
|
func FileHashFormatted(path string) (string, error) {
|
|
h, err := FileHash(path)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return fmt.Sprintf("sha256:%s", h), nil
|
|
}
|