filestat

package
v0.0.0-...-8685a14 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package filestat defines and implements basic file statistics interface

Package fh implements basic hashing functionality

Index

Constants

View Source
const (
	Idle   = ""
	MD5    = "md5"
	SHA1   = "sha1"
	SHA256 = "sha256"
	SHA512 = "sha512"
)
View Source
const EMPTY_CHECKSUM = "-"

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSizeLesserFunc

type FileSizeLesserFunc func(fs FileStat) bool

func NewFileSizeLesserFunc

func NewFileSizeLesserFunc(maxSize int64, inBlocks bool) FileSizeLesserFunc

type FileStat

type FileStat interface {
	// Path - full path (abs cleaned resolved)
	Path() string
	// BaseName - file name wo dirs
	BaseName() string
	// Inode - Unix inode (or analogue) used here to resolve multiple links to the same file content
	Inode() Inode
	// IsRegular - checks whether file is regular (FileMode & ModeType == 0)
	IsRegular() bool
	// Size - content size
	Size() int64
	// Blksize - block size of file (file system specific)
	Blksize() int64
	// Blocks - number of blocks occupied by file (here it's calculated as Blocks = Ceil (Size / Blksize) )
	Blocks() int64
	// ModTime - modification time
	ModTime() time.Time
	// Perm - Unix permission bits (or analogue)
	Perm() fs.FileMode
	// User - user owner of file
	User() *user.User
	// Group - group owner of file
	Group() *user.Group
	// Symlink - initial (from search matching) link to this file
	Symlink() FileStat
	// MetaKey - custom key based on file metadata (such as name, size, uid:gid, perm, ...)
	// Note: content itself is ignored - see FileStatMetaKeyFunc for details
	MetaKey() string
	// String - pretty string for view (like ls -i)
	String() string
	//
	Prior() string
	// SortingKey - sorting key for output
	SortingKey() string
}

FileStat describes a file (use GetFileStat)

func GetFileStat

func GetFileStat(path string, metaKeyFunc MetaKeyFunc, priorFunc PriorFunc, SymLinkEnabled bool) (FileStat, error)

GetFileStat - FileStat builder function (uses os specific func newFileStat)

type FileStatValidatorFunc

type FileStatValidatorFunc func(fs FileStat) bool

func NewRegularSizeStatValidator

func NewRegularSizeStatValidator(minSize, maxSize int64) FileStatValidatorFunc

todo: make validators stack

type HashFileFunc

type HashFileFunc func(fs FileStat, prefix string) (result string, written int64, err error)

HashFileFunc - type specifies signature of function that calculates hash / checksum for file path initial settings (algo, size, etc.) are taken from closure - see GetHashFileFunc

func GetHashFileFunc

func GetHashFileFunc(algo string, ndMaxSize int64, inBlocks bool) (HashFileFunc, error)

GetHashFileFunc customizes hasher func

type Inode

type Inode uint64

type MetaKeyFunc

type MetaKeyFunc func(fs FileStat) string

FileStatMetaKeyFunc - func type for meta key builder (used in FileStat.MetaKey()) see NewMetaKeyFunc

func NewMetaKeyFunc

func NewMetaKeyFunc(bSize bool, bName bool, bPerm bool, bUID bool, bGID bool, bModTime bool) MetaKeyFunc

NewMetaKeyFunc customizes meta key builder function (enclosure for FileStatMetaKeyFunc) todo: make keys set order to be also customizable - thus, it will be possible to set sorting order by meta key.

type PriorFunc

type PriorFunc func(path string) string

func NewPriorFunc

func NewPriorFunc(roots []string) PriorFunc

Jump to

Keyboard shortcuts

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