CRC32 Checksum Calculation via GO


Trying to create a GO function that produces the same result as the Ubuntu Linux "cksum" operation, for example:

$ echo 123 > /tmp/foo
$ cksum /tmp/foo
2330645186 4 /tmp/foo

Could someone please provide a GO function that produces the first substring of the above result ("2330645186")? Thank you.


Actually, I found a more simplified answer to my original question:


Here is the snippet that provides the posix checksum equivalent value of a file in Go:

path := "/tmp/test.loop"
data, err := ioutil.ReadFile(path)
if err != nil {
h := cksum.New()
io.WriteString(h, string(data))
fmt.Printf("cksum: %d\n", h.Sum32())

Answered By – Ben Jafari

Answer Checked By – Dawn Plyler (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.