awesome-go/impl/files_manipulation/HasAndChecksum2.go

34 lines
441 B
Go

package main
import (
"crypto/md5"
"fmt"
"io"
"log"
"os"
)
func main() {
/*
Hashing and Checksums
*/
// Open file for reading
file, err := os.Open("test.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
// Create new hasher, which is a writer interface
hasher := md5.New()
_, err = io.Copy(hasher, file)
if err != nil {
log.Fatal(err)
}
sum := hasher.Sum(nil)
fmt.Printf("Md5 checksum: %x\n", sum)
}