Golang hash/crc32.ChecksumIEEE function examples
package hash/crc32
ChecksumIEEE returns the CRC-32 checksum of data using the IEEE polynomial.
Golang hash/crc32.ChecksumIEEE function usage examples
Example 1:
package main
import (
"fmt"
"hash/crc32"
)
func main() {
checksum := crc32.ChecksumIEEE([]byte("abcd"))
fmt.Printf("Checksum : %x \n", checksum)
}
Example 2:
// Check checksum.
var checksum uint32
n, err := fmt.Fscanf(file, "x\n", &checksum)
if err != nil {
fmt.Println(err)
} else if n != 1 {
fmt.Println("checksum.err: bad.snapshot.file")
}
// Load remaining snapshot contents.
b, err := ioutil.ReadAll(file)
if err != nil {
fmt.Println(err)
}
// Generate checksum.
byteChecksum := crc32.ChecksumIEEE(b)
if uint32(checksum) != byteChecksum {
fmt.Println("bad snapshot file")
}
References :
Advertisement
Something interesting
Tutorials
+6.3k Apt-get to install and uninstall Golang
+22k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+9.1k Golang : Handle sub domain with Gin
+6.2k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)
+14.6k Golang : Reset buffer example
+7.1k Golang : Squaring elements in array
+28k Golang : Move file to another directory
+11.1k Golang : Web routing/multiplex example
+5.4k Unix/Linux/MacOSx : How to remove an environment variable ?
+12.8k Golang : Listen and Serve on sub domain example
+6.5k Golang : Map within a map example