crc32a

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2019 License: MIT Imports: 2 Imported by: 1

README

CRC32A

A pure Go implementation of CRC32A (ITU I.363.5) checksum missing from Golang standard library. Largely based on C implementation found in PHP source files.

Usage

package main

import (
	"fmt"
	
	"github.com/boguslaw-wojcik/crc32a"
)

func main() {
	b := []byte("123456789")
	sum := crc32a.Checksum(b)
	sumHex := crc32a.ChecksumHex(b)

	fmt.Println(sum)    // 404326908
	fmt.Println(sumHex) // 181989fc
}

Background

There are four popular implementations of CRC32 of which three are included in Golang standard library. This package provides missing implementation of CRC32A (ITU I.363.5) popularized by bzip2 and PHP. If you're unsure what CRC32 algorithm you're using, calculate checksum for string 123456789 and compare results with the table below.

Variant Performance Standard Library Data Hex Sum
CRC32A (ITU I.363.5) 31.4 ns/op no 123456789 181989fc 404326908
CRC32B (ITU V.42 / IEEE 802.3) 24.0 ns/op yes 123456789 cbf43926 3421780262
CRC32C (Castagnoli) 15.2 ns/op yes 123456789 e3069283 3808858755
CRC32K (Koopman) 4534 ns/op yes 123456789 2d3dd0ae 759025838

Note: Unless you're required to use CRC32A for legacy reasons, in general you should choose CRC32B as the most popular and widely implemented CRC32 variation.

References

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Checksum

func Checksum(data []byte) uint32

Checksum calculates CRC32A (ITU I.363.5 algorithm, popularized by BZIP2) checksum. This function will produce the same results as following PHP code:

hexdec(hash('crc32', $data))

func ChecksumHex

func ChecksumHex(data []byte) string

ChecksumHex is a convenience function that outputs CRC32A (ITU I.363.5 algorithm, popularized by BZIP2) checksum as a hex string. This function will produce the same results as following PHP code:

hash('crc32', $data)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL