summaryrefslogtreecommitdiff
path: root/shelf/hash.go
diff options
context:
space:
mode:
authorJonas Knobloch <jonas.knobloch@t-online.de>2026-04-23 18:14:50 +0200
committerJonas Knobloch <jonas.knobloch@t-online.de>2026-04-23 20:21:12 +0200
commit875ac19922932b12f6357d64a460c06d031000e7 (patch)
treef4f268ef2b029a5e187613d6ebbec1a166615dbc /shelf/hash.go
parentd35f5fad1d26fc09cfd98f6e7faf17d6a48e4e8f (diff)
Add shelf module
Diffstat (limited to 'shelf/hash.go')
-rw-r--r--shelf/hash.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/shelf/hash.go b/shelf/hash.go
new file mode 100644
index 0000000..eea81d5
--- /dev/null
+++ b/shelf/hash.go
@@ -0,0 +1,28 @@
+package shelf
+
+import (
+ "crypto/sha256"
+ "encoding/hex"
+ "io"
+ "os"
+)
+
+func hashFile(name string) (string, error) {
+ var file *os.File
+
+ if f, err := os.Open(name); err != nil {
+ return "", err
+ } else {
+ file = f
+ }
+
+ defer file.Close()
+
+ hash := sha256.New()
+
+ if _, err := io.Copy(hash, file); err != nil {
+ return "", err
+ }
+
+ return hex.EncodeToString(hash.Sum(nil)), nil
+}