Documentation
¶
Index ¶
- Variables
- type EqualSizes
- type FileInfo
- type Node
- func (node *Node) EqualSizes() map[int64]*EqualSizes
- func (node *Node) GetBiggest(biggest *Node) *Node
- func (node *Node) GetFile(name string) (*Node, error)
- func (node *Node) GetFileByAbsolutePath(path string) (*Node, error)
- func (node *Node) GetFileByPath(filePath string) (*Node, error)
- func (node *Node) GetFileByPatternAndExt(pattern string, ext string) (*Node, error)
- func (node *Node) GetFileBySizeAndExt(size int64, ext string, exclude ...string) (*Node, error)
- func (node *Node) GetFiles(ext ...string) []*Node
- func (node *Node) Remove() error
- func (node *Node) UpdateFileInfo() error
Constants ¶
This section is empty.
Variables ¶
var (
ErrNotFound = errors.New("file not found")
)
Functions ¶
This section is empty.
Types ¶
type EqualSizes ¶
EqualSizes represents a collection of files that share the same size.
type FileInfo ¶
type FileInfo struct { Name string `json:"name"` Size int64 `json:"size"` IsDir bool `json:"is_dir"` Mode os.FileMode `json:"mode"` ModTime time.Time `json:"mod_time"` Extension string `json:"ext"` }
FileInfo is a struct created from os.FileInfo interface for serialization.
func FileInfoFromInterface ¶
FileInfoFromInterface is a helper function to create a local FileInfo struct from os.FileInfo interface.
func GetFileInfo ¶
GetFileInfo retrieves file information for the file at the given path and returns it as a FileInfo struct.
type Node ¶
type Node struct { FullPath string `json:"path"` Info *FileInfo `json:"info"` Children []*Node `json:"children"` Parent *Node `json:"-"` }
Node represents a node in a directory tree.
func BuildFileTree ¶
BuildFileTree constructs a hierarchical file tree from a map of nodes, identifying the root and linking children. It associates parent nodes with their children and sorts the tree nodes recursively. Panics if no root node is identified.
func Collect ¶
Collect traverses a directory structure starting at the given root path and constructs a hierarchical representation. Returns the root node of the constructed file tree or an error if traversal fails.
func (*Node) EqualSizes ¶
func (node *Node) EqualSizes() map[int64]*EqualSizes
EqualSizes returns a map of files with the same size.
func (*Node) GetBiggest ¶
GetBiggest traverses the node hierarchy to find the file with the largest size. Returns the largest file encountered.
func (*Node) GetFileByAbsolutePath ¶
GetFileByAbsolutePath returns a single file by its absolute path.
func (*Node) GetFileByPath ¶
GetFileByPath returns a single file by its path.
func (*Node) GetFileByPatternAndExt ¶
GetFileByPatternAndExt returns the first match for a given pattern and extension.
func (*Node) GetFileBySizeAndExt ¶
GetFileBySizeAndExt returns a single file by its size and extension.
func (*Node) GetFiles ¶
GetFiles returns all files or only files with a given extension. The extension must include the dot, e.g. ".mkv".
func (*Node) UpdateFileInfo ¶
UpdateFileInfo updates the node's FileInfo by retrieving and parsing the file metadata of its associated path.