Documentation
¶
Overview ¶
Package objectify reads a provided directory and turns each directory entry / file into an object. Each object (FileObj) contains calculated checksums, symlink target paths, size and file mode information, and provides functions to check for recent modifications.
Index ¶
- Constants
- type Action
- type FileObj
- func (fo *FileObj) ChangeSets(s Sets)
- func (fo *FileObj) DebugOut()
- func (fo *FileObj) Force(a Action)
- func (fo *FileObj) FullPath() string
- func (fo *FileObj) HasChanged() bool
- func (fo *FileObj) SecondsSinceUpdatedAt() int64
- func (fo *FileObj) SizeString() string
- func (fo *FileObj) Update() *FileObj
- type Files
- type Sets
Constants ¶
const (
EMPTY = ""
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileObj ¶
type FileObj struct {
// UpdatedAt represents the last time this struct was updated.
UpdatedAt time.Time
// Filename is the base name of the directory entry.
// Root is the parent directory.
Filename string
Root string
// SizeBytes is the size of the file in Bytes.
SizeBytes int64
// ChecksumMD5 and ChecksumSHA256 are hash byte array string-representations.
// MD5 and SHA256 are the hash byte arrays.
ChecksumMD5 string
MD5 []byte
ChecksumSHA256 string
SHA256 []byte
// Mode is the entMode of the directory entry.
// modeFS is returned from os.Lstat
Mode entMode
// Target will be populated with a symlinks target path.
Target string
IsLink bool
IsReadable bool
IsExists bool
Set *Sets
// contains filtered or unexported fields
}
FileObj represents a directory entry object.
func (*FileObj) ChangeSets ¶
ChangeSets overwrites the Set field with a new Sets object.
func (*FileObj) Force ¶
Force applies the specified action to the FileObj by changing its sets and calling the corresponding helper methods. The original sets of the FileObj are stored temporarily and restored after applying the action. The available actions are:
- F_CHECKSUM_MD5: Changes the sets to enable checksum MD5 calculation and calls the setChecksums() method.
- F_CHECKSUM_SHA256: Changes the sets to enable checksum SHA256 calculation and calls the setChecksums() method.
- F_MODES: Changes the sets to enable mode and file info retrieval and calls the setModeAndFileInfo() method.
- F_SIZE: Changes the sets to enable size calculation and calls the setSize() method.
- F_LINKTARGET: Changes the sets to enable link target retrieval and calls the setTarget() method.
func (*FileObj) FullPath ¶
FullPath returns the full path of the FileObj by joining the Root and Filename. Utilizes filepath.Join to combine the two components.
func (*FileObj) HasChanged ¶
HasChanged checks if the file specified by FileObj has been modified since its last update. It returns true if the file exists, is readable, and its modification time is after the last update time. Otherwise, it returns false.
func (*FileObj) SecondsSinceUpdatedAt ¶
SecondsSinceUpdatedAt returns the number of seconds since the UpdatedAt time of the FileObj.
func (*FileObj) SizeString ¶
SizeString returns the formatted string representation of the size in bytes. Converts the given size in bytes to a human-readable format (e.g., KB, MB, GB, etc.).
type Files ¶
type Files []*FileObj
func Objectify ¶
Objectify is a function that takes a rootPath and a Sets struct as parameters. It creates a worker instance and runs it using the run function to collect file information. It returns a slice of FileObj structs and an error if any. The Sets struct is used to specify which fields of the FileObj struct need to be populated.
type Sets ¶
Sets fields are flags for FileObj fields which can be optionally populated.
func SetsAllMD5 ¶
func SetsAllMD5() Sets
SetsAllMD5 returns a Sets object with all fields set to true, except for ChecksumSHA256.
func SetsAllNoChecksums ¶
func SetsAllNoChecksums() Sets
SetsAllNoChecksums sets all fields of the Sets object to true, except for the ChecksumMD5 and ChecksumSHA256.
func SetsAllSHA256 ¶
func SetsAllSHA256() Sets
SetsAllSHA256 returns a Sets object with all fields set to true, except for ChecksumMD5.