summaryrefslogtreecommitdiff
path: root/md5sum.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2019-06-13 19:31:37 -0700
committerJeff Carr <[email protected]>2019-06-13 19:31:37 -0700
commit49d36e287d983f72b2b2b5d903fb3bf55a44b440 (patch)
treea34470c22f127b9405c2f62527af0cce934192be /md5sum.go
parentb375aa752a6e587a8d5b3408965ac8029c2eeee8 (diff)
start handling stupid Windows
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'md5sum.go')
-rw-r--r--md5sum.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/md5sum.go b/md5sum.go
new file mode 100644
index 0000000..74ec106
--- /dev/null
+++ b/md5sum.go
@@ -0,0 +1,35 @@
+package shell
+
+import "crypto/md5"
+import "encoding/hex"
+import "log"
+import "io"
+import "os"
+
+func hash_file_md5(filePath string) (string, error) {
+ var returnMD5String string
+ file, err := os.Open(filePath)
+ if err != nil {
+ return returnMD5String, err
+ }
+ defer file.Close()
+ hash := md5.New()
+ if _, err := io.Copy(hash, file); err != nil {
+ return returnMD5String, err
+ }
+ hashInBytes := hash.Sum(nil)[:16]
+ returnMD5String = hex.EncodeToString(hashInBytes)
+ return returnMD5String, nil
+
+}
+
+// hash thyself: hash_file_md5(os.Args[0])
+func Md5sum(filename string) string {
+ hash, err := hash_file_md5(filename)
+ if err == nil {
+ log.Println("shell.Md5sum() hash =", hash)
+ return hash
+ }
+ log.Println("shell.Md5sum() failed")
+ return ""
+}