hashutil

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 17 Imported by: 8

Documentation

Index

Constants

View Source
const (
	// DefaultHash the default hash algorithm
	DefaultHash = MD5Hash
	// MD5Hash the MD5 hash algorithm
	MD5Hash = "md5"
	// SHA1Hash the SHA-1 hash algorithm
	SHA1Hash = "sha1"
	// SHA256Hash the SHA256 hash algorithm
	SHA256Hash = "sha256"
	// SHA512Hash the SHA-512 hash algorithm
	SHA512Hash = "sha512"
	// CRC32Hash the CRC-32 checksum
	CRC32Hash = "crc32"
	// CRC64Hash the CRC-64 checksum
	CRC64Hash = "crc64"
	// Adler32Hash the Adler-32 checksum
	Adler32Hash = "adler32"
	// FNV132Hash the 32-bit FNV-1 non-cryptographic hash function
	FNV132Hash = "fnv-1-32"
	// FNV1A32Hash the 32-bit FNV-1a non-cryptographic hash function
	FNV1A32Hash = "fnv-1a-32"
	// FNV164Hash the 64-bit FNV-1 non-cryptographic hash function
	FNV164Hash = "fnv-1-64"
	// FNV1A64Hash the 64-bit FNV-1a non-cryptographic hash function
	FNV1A64Hash = "fnv-1a-64"
	// FNV1128Hash the 128-bit FNV-1 non-cryptographic hash function
	FNV1128Hash = "fnv-1-128"
	// FNV1A128Hash the 128-bit FNV-1a non-cryptographic hash function
	FNV1A128Hash = "fnv-1a-128"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Hash

type Hash interface {
	// HashFromFile calculate the hash value of the file
	// If you reuse the file reader, please set its offset to start position first, like os.File.Seek
	HashFromFile(file io.Reader) (hashString string, err error)
	// HashFromFileName calculate the hash value of the file
	HashFromFileName(path string) (hash string, err error)
	// HashFromFileChunk calculate the hash value of the file chunk
	HashFromFileChunk(path string, offset int64, chunkSize int64) (hash string, err error)
	// Hash calculate the hash value of the bytes
	Hash(bytes []byte) (hashString string)
	// HashFromString calculate the hash value of the string
	HashFromString(s string) (hash string)
	// CheckpointsHashFromFileName calculate the hash value of the entire file and first chunk and some checkpoints
	// the first chunk hash is optional
	// the checkpoint hash is optional
	// the entire file hash is required
	CheckpointsHashFromFileName(path string, chunkSize int64, checkpointCount int) (hvs HashValues, err error)
	// CheckpointsHashFromFile calculate the hash value of the entire file and first chunk and some checkpoints
	CheckpointsHashFromFile(f *os.File, chunkSize int64, checkpointCount int) (hvs HashValues, err error)
	// GetFileSizeAndHashCheckpoints get the file size and hash checkpoints from the specified file
	GetFileSizeAndHashCheckpoints(path string, chunkSize int64, checkpointCount int) (size int64, hash string, hvs HashValues, err error)
	// Compare whether the source file is equal to the destination file
	Compare(chunkSize int64, checkpointCount int, sourceFile *os.File, sourceSize int64, dest string, destSize int64, offset *int64) (equal bool)
	// QuickCompare if the forceChecksum is false, check whether the size and time are both equal, otherwise return false
	QuickCompare(forceChecksum bool, sourceSize, destSize int64, sourceModTime, destModTime time.Time) (equal bool)
	// CompareHashValues compare the HashValues from source file with the destination file
	CompareHashValues(dstPath string, sourceSize int64, sourceHash string, chunkSize int64, hvs HashValues) (equal bool, hv *HashValue)
	// CompareHashValuesWithFileName calculate the file hashes and return the last continuous hit HashValue.
	// The offset in the HashValues must equal chunkSize * N, and N greater than zero
	CompareHashValuesWithFileName(path string, chunkSize int64, hvs HashValues) (eq *HashValue, err error)
}

Hash a hash calculate component

func NewHash

func NewHash(algorithm string) (Hash, error)

NewHash return the hash implementation by the specified hash algorithm

type HashValue

type HashValue struct {
	// Offset the file data to calculate the hash value from zero to offset
	Offset int64 `json:"offset"`
	// Hash the file checkpoint hash value
	Hash string `json:"hash"`
}

HashValue the file hash info

func NewHashValue

func NewHashValue(offset int64, hash string) *HashValue

NewHashValue returns an instance of HashValue

type HashValues

type HashValues []*HashValue

HashValues the list of *HashValue

func (HashValues) Last

func (hvs HashValues) Last() *HashValue

Last returns the last element of HashValues

Jump to

Keyboard shortcuts

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