hashcache

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CheckSumFileName is the checksum file name (base with no directories)
	DefaultCheckSumFileName = "checksum.txt"
)

Variables

This section is empty.

Functions

func CalcChecksum

func CalcChecksum(file string) (string, error)

CalcChecksum works out the checksum string

func GetCachedChecksum

func GetCachedChecksum(file string) (string, error)

GetCachedChecksum will return previously calculated checksum

func GetFiles

func GetFiles(path string) []string

GetFiles will return a list of files from cache

Types

type CheckSumCache added in v0.2.0

type CheckSumCache struct {
	AddedItems          []CheckSumItem
	CheckSumsByFilePath map[string]CheckSumItem
	CheckSumFile        string
	Dir                 string
}

CheckSumCache defines data for a hash cache

func NewFromCheckSumsFile added in v0.2.0

func NewFromCheckSumsFile(file string, errIfMissing bool) (c *CheckSumCache, err error)

NewCacheFromCheckSumsFile creates a cache interface from a specific checksum file

func NewFromDir added in v0.2.0

func NewFromDir(dir string, errIfMissing bool) (c *CheckSumCache, err error)

NewCacheFromDir instanciates a cache using the default cache file name given a directory. Optionally error if checksum file is missing

func NewFromExistingFile added in v0.2.0

func NewFromExistingFile(
	file string,
	create bool) (c *CheckSumCache, err error)

NewFromExistingFile creates an existing cache (relative from the file name) optionally will create the cache item...

func (*CheckSumCache) Clean added in v0.3.6

func (c *CheckSumCache) Clean() error

Clean will remove any old entries (not added using Update method)

func (*CheckSumCache) IsCached added in v0.2.0

func (c *CheckSumCache) IsCached(file string) bool

IsCached will check if a file is present on disk and in the checksum file

func (*CheckSumCache) IsCachedMatched added in v0.2.0

func (c *CheckSumCache) IsCachedMatched(file string, sha256 string) bool

IsCachedMatched will verify if a file is in Cache AND matching expected sha256

func (*CheckSumCache) IsCachedMatchingFile added in v0.3.10

func (c *CheckSumCache) IsCachedMatchingFile(file string) bool

IsCachedMatchingFile will check if the cache checksum matches calculated

func (*CheckSumCache) Keep added in v0.3.8

func (c *CheckSumCache) Keep(file string)

Keep will mark a file (and checksum) so it won't be cleaned with .Clean

func (*CheckSumCache) Update added in v0.2.0

func (c *CheckSumCache) Update(file string) (checksum string, err error)

Update will update (or add) a file to the cache (checksum file)

type CheckSumItem added in v0.2.0

type CheckSumItem struct {
	// CheckSum is the sha256sum initialy calculated
	CheckSum string
	// CheckSumCached indicates if the checksum has been calculated or cached
	CheckSumCached bool
	// FilePath is the full path to a file given a start directory
	FilePath string
	// FileName is a relative file name only
	FileName string
}

CheckSumItem represents a single file as present in cache (checksum file)

Jump to

Keyboard shortcuts

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