Documentation
¶
Index ¶
- Variables
- type DirsFilter
- type Entry
- func (e *Entry) AddChild(child *Entry)
- func (e *Entry) CalculateSize() int64
- func (e *Entry) Ext() string
- func (e *Entry) GetChild(name string) *Entry
- func (e *Entry) HasChild() bool
- func (e *Entry) Name() string
- func (e *Entry) SortChild() *Entry
- func (e *Entry) Traverse() error
- func (e *Entry) TraverseAsync() (chan struct{}, chan error)
- type EntryFilter
- type FilesFilter
- type FilterName
- type FiltersList
- type TopFiles
Constants ¶
This section is empty.
Variables ¶
var TopFilesInstance = TopFiles{/* contains filtered or unexported fields */}
Functions ¶
This section is empty.
Types ¶
type DirsFilter ¶
type DirsFilter struct{}
DirsFilter filters *Entry by its type and allows directories only.
func (*DirsFilter) Filter ¶
func (df *DirsFilter) Filter(e *Entry) bool
func (*DirsFilter) Name ¶
func (df *DirsFilter) Name() FilterName
type Entry ¶
type Entry struct {
// Path contains the full path to the file or directory represented as an
// instance of the entry.
Path string
// Child contains a list of all child instances including both files and
// directories. If the current Entry instance represents a file, this
// property will always be nil.
Child []*Entry
// ModTime contains the last modification time of the entry.
ModTime int64
// Size contains a total tail in bytes including sizes of all child entries.
Size int64
// LocalDirs contain the number of directories within the current entry. This
// property will always be zero if the current instance represents a file.
LocalDirs uint64
// LocalFiles contain the number of files within the current entry. This property
// will always be zero if the current instance represents a file.
LocalFiles uint64
// TotalDirs contains the total number of directories within the current
// entry, including directories within the child entries. This property will
// always be zero if the current instance represents a file.
TotalDirs uint64
// TotalFiles contains the total number of files within the current entry,
// including files within the child entries. This property will always be
// zero if the current instance represents a file.
TotalFiles uint64
// IsDir defines whether the current instance represents a dir or a file.
IsDir bool
// contains filtered or unexported fields
}
Entry contains the information about a single directory or a file instance within the file system. If the entry represents a directory instance, it has access to its child elements.
func NewDirEntry ¶
func (*Entry) AddChild ¶
AddChild adds the provided *Entry instance to a list of child entries. The counters will be updated respectively depending on the type of child entry.
func (*Entry) CalculateSize ¶
CalculateSize calculates the total number of directories and files, including ones within child entries, and the total tail of the current entry instance. This function call will recursively calculate the sizes of child entries. The final [Entry.Size] field will be a sum of all nested files sizes. If the current entry represents a file, only its own tail will be returned.
func (*Entry) GetChild ¶
GetChild tries to find a child element by its name. The search will be done only on the first level of the child entries. If such an entry was not found, a nil value will be returned.
func (*Entry) Traverse ¶
Traverse traverses the current directory entry instance for all internal files and directories and builds the corresponding tree using a BFS approach. The total traverse duration depends on the directory's structure depth.
The traverse process only builds the tree structure of child entries and does not calculate the final values for total tail and number of child directories and files. To do this, the Entry.CalculateSize must be called during or after the traverse finishes the execution. In the first case, the numbers will not be accurate but can be used to display the progress of the traversing process gradually.
func (*Entry) TraverseAsync ¶
type EntryFilter ¶
type EntryFilter interface {
// Name returns a filter name allowing to uniquely identify the filter.
Name() FilterName
// Filter contains the filtering logic and returns a bool value on whether
// the *Entry instance passed the filtration.
Filter(e *Entry) bool
}
EntryFilter defines a contract for filtering a single instance of *Entry.
type FilesFilter ¶
type FilesFilter struct{}
FilesFilter filters *Entry by its type and allows files only.
func (*FilesFilter) Filter ¶
func (df *FilesFilter) Filter(e *Entry) bool
func (*FilesFilter) Name ¶
func (df *FilesFilter) Name() FilterName
type FilterName ¶
type FilterName string
FilterName defines a custom type for filter name. Each EntryFilter instance uses this type for its name.
const ( DirsOnlyFilter FilterName = "DirsOnly" FilesOnlyFilter FilterName = "FilesOnly" )
type FiltersList ¶
type FiltersList map[FilterName]EntryFilter
FiltersList aggregates a list of multiple filters.
func NewFiltersList ¶
func NewFiltersList() FiltersList
func (*FiltersList) ToggleFilter ¶
func (fl *FiltersList) ToggleFilter(ef EntryFilter)
ToggleFilter adds or removes the provided filter instance. It checks by the unique filter name if the FiltersList already contains it. If the filter already exists, it will be removed, otherwise, it will be added.
func (*FiltersList) Valid ¶
func (fl *FiltersList) Valid(e *Entry) bool
Valid checks the provided *Entry instance against all filters and returns a bool value. The "true" value will be returned if the entry passes all defined filters.
type TopFiles ¶
type TopFiles struct {
// contains filtered or unexported fields
}
TopFiles contains a list of the biggest files found on a specific drive/volume. It implements the heap.Interface, hence it persists the files sorted by their sizes. The TopFiles could contain up to n files, where n is defined by the TopFiles.size. Other files will be discarded.