cksum

package module
v0.0.0-...-c900aea Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: MIT Imports: 2 Imported by: 0

README

Posix cksum implementation in go

The CRC-32 checksum, and the checksum generated for Posix cksum are slightly different despite starting with the same polynomial. Maybe this is why people people have moved on to MD5 or SHA based checksums.

If you wish to generated CRC-32 checksums the hash/CRC32 package (using the ChecksumIEEE method) will work just fine. You can compare results of this with the online tool found here

For a posix cksum version, I've instead implemented the C code found here in golang (a table based calculator). For reference I also built a non-table version (see: cksum-nt.go)

Usage

package main

import (
    "fmt"
    "github.com/gnabgib/go-cksum"
    "os"
)

func main() {
    file := "eg-file.txt"
    f,err := os.Open(file)
    if err != nil {
		fmt.Println("Unable to find file",filename)
		return
    }
    defer f.Close()
	in := bufio.NewReader(f)
    crc, size, err := Stream(in)
    if err!=nil {
        fmt.Println("CRC error:",err)
        return
    }
    fmt.Printf("%d %d %s",crc,size,file)
}

Documentation

Overview

Package cksum copyright 2020, gnabgib Use of this source code is governed by the LICENSE file

Tableless version of the cksum algorithm, smaller binaries, probably slower execution

  • Note the type (crcNt) and the helpers (streamNt, bytesNt) are not exported, you're not expected to use this implementation but rhather cksum.go

Package cksum copyright 2020, gnabgib Use of this source code is governed by the LICENSE file

Table backed version the cksum algorithm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes(data []byte) (uint32, int, error)

Bytes - Calculate checksum of a byte slice

func Stream

func Stream(r *bufio.Reader) (uint32, int, error)

Stream - Calculate checksum of a stream

Types

This section is empty.

Jump to

Keyboard shortcuts

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