Created
March 25, 2015 06:44
-
-
Save ohodoa/0f06c9ae835c0b21f5fb to your computer and use it in GitHub Desktop.
golang md5 file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/md5" | |
"os" | |
"io" | |
"log" | |
"encoding/hex" | |
) | |
func main() { | |
h := md5.New() | |
f, err := os.Open(os.Args[1]) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer f.Close() | |
if _, err := io.Copy(h, f); err != nil { | |
log.Fatal(err) | |
} | |
os.Stdout.WriteString(hex.EncodeToString(h.Sum(nil))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another alternative is to use: