util

package
v0.31.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Escape

func Escape(a string) string

Escape * Tab is escaped as `\t`. * Carriage return is escaped as `\r`. * Line feed is escaped as `\n`. * Single quote is escaped as `\'`. * Double quote is escaped as `\"`. * Backslash is escaped as `\\`.

func Evallinks(fullPath string) (string, error)

func IsExecutable

func IsExecutable(file os.FileInfo) bool

func IsExecutableMode

func IsExecutableMode(mode os.FileMode) bool
func IsSymLink(file os.FileInfo) bool

func IsSymLinkMode

func IsSymLinkMode(mode os.FileMode) bool

func JaroWinkler added in v0.31.0

func JaroWinkler(a, b string, boostThreshold float64, prefixSize int) float64
func MakeLink(abs, name string) string

func RecursivelySizeOf

func RecursivelySizeOf(info *item.FileInfo, depth int) int64

RecursivelySizeOf returns the size of the file or directory depth < 0 means no limit

func RemoveSep

func RemoveSep(s string) string

func SplitNumberAndUnit added in v0.27.0

func SplitNumberAndUnit(input string) (float64, string)

SplitNumberAndUnit splits a string like "10bit" to 10 and "bit"

"12.3ml" to 12.4 and "ml"

"-1,234,213kg" to -1234213 and "kg"

func SupportsHyperlinks() bool

Types

type BatchDirectoryProcessor added in v0.31.2

type BatchDirectoryProcessor struct {
	// contains filtered or unexported fields
}

BatchDirectoryProcessor implements batch processing with optimizations Designed for larger directories and complex operations

func (*BatchDirectoryProcessor) ProcessDirectory added in v0.31.2

func (bdp *BatchDirectoryProcessor) ProcessDirectory(dirPath string) ([]*item.FileInfo, []error)

ProcessDirectory processes directory using batch approach for larger datasets

type BatchFileInfo added in v0.31.2

type BatchFileInfo struct {
	// contains filtered or unexported fields
}

BatchFileInfo provides batch file information retrieval to reduce system calls

func NewBatchFileInfo added in v0.31.2

func NewBatchFileInfo(parent string) (*BatchFileInfo, error)

NewBatchFileInfo creates a new batch file info reader

func (*BatchFileInfo) GetCount added in v0.31.2

func (b *BatchFileInfo) GetCount() int

GetCount returns the number of files in the directory for pre-allocation

func (*BatchFileInfo) GetDirectoryCount added in v0.31.2

func (b *BatchFileInfo) GetDirectoryCount() int

GetDirectoryCount returns the number of subdirectories for more accurate pre-allocation

func (*BatchFileInfo) GetFileInfos added in v0.31.2

func (b *BatchFileInfo) GetFileInfos() ([]*item.FileInfo, []error)

GetFileInfos retrieves file information in batch with pre-allocated memory and string optimizations

func (*BatchFileInfo) HasSubdirectories added in v0.31.2

func (b *BatchFileInfo) HasSubdirectories() bool

HasSubdirectories checks if there are subdirectories for recursive optimization

type DirectoryProcessor added in v0.31.2

type DirectoryProcessor interface {
	ProcessDirectory(dirPath string) ([]*item.FileInfo, []error)
}

DirectoryProcessor defines interface for different directory processing strategies

type MockFileInfo added in v0.28.0

type MockFileInfo struct {
	// contains filtered or unexported fields
}

func NewMockFileInfo added in v0.28.0

func NewMockFileInfo(size int64, isDir bool, name string, mode os.FileMode, modTime time.Time) *MockFileInfo

func (*MockFileInfo) IsDir added in v0.28.0

func (m *MockFileInfo) IsDir() bool

func (*MockFileInfo) ModTime added in v0.28.0

func (m *MockFileInfo) ModTime() time.Time

func (*MockFileInfo) Mode added in v0.28.0

func (m *MockFileInfo) Mode() os.FileMode

func (*MockFileInfo) Name added in v0.28.0

func (m *MockFileInfo) Name() string

func (*MockFileInfo) Size added in v0.28.0

func (m *MockFileInfo) Size() int64

func (*MockFileInfo) Sys added in v0.28.0

func (m *MockFileInfo) Sys() any

type Once

type Once struct {
	// contains filtered or unexported fields
}

func (*Once) Do

func (o *Once) Do(fn func() error) error

type OptimizationStrategy added in v0.31.2

type OptimizationStrategy struct {
	// Thresholds for strategy selection
	SmallDirThreshold int  // Files count below which to use traditional approach
	BatchModeEnabled  bool // Global toggle for batch mode
}

OptimizationStrategy determines which processing strategy to use

func NewOptimizationStrategy added in v0.31.2

func NewOptimizationStrategy() *OptimizationStrategy

NewOptimizationStrategy creates a new strategy selector with default values

func (*OptimizationStrategy) EstimateDirectorySize added in v0.31.2

func (ots *OptimizationStrategy) EstimateDirectorySize(dirPath string) int

EstimateDirectorySize provides a quick estimate without full directory read

func (*OptimizationStrategy) SelectProcessor added in v0.31.2

func (ots *OptimizationStrategy) SelectProcessor(dirPath, outputFormat string, hasComplexFiltering bool) DirectoryProcessor

SelectProcessor chooses the optimal processing strategy based on context

type SafeSet

type SafeSet[T constval.Hashable] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[T constval.Hashable]() *SafeSet[T]

func (*SafeSet[T]) Add

func (s *SafeSet[T]) Add(k T)

func (*SafeSet[T]) Contains

func (s *SafeSet[T]) Contains(k T) bool

type Slice

type Slice[T any] struct {
	// contains filtered or unexported fields
}

func NewSlice

func NewSlice[T any](size int) *Slice[T]

func (*Slice[T]) AppendTo

func (s *Slice[T]) AppendTo(d T)

func (*Slice[T]) At

func (s *Slice[T]) At(pos int) T

func (*Slice[T]) Clear

func (s *Slice[T]) Clear()

func (*Slice[T]) GetCopy

func (s *Slice[T]) GetCopy() []T

func (*Slice[T]) GetRaw

func (s *Slice[T]) GetRaw() *[]T

func (*Slice[T]) Len

func (s *Slice[T]) Len() int

func (*Slice[T]) Set

func (s *Slice[T]) Set(pos int, d T)

type TraditionalDirectoryProcessor added in v0.31.2

type TraditionalDirectoryProcessor struct {
	// contains filtered or unexported fields
}

TraditionalDirectoryProcessor implements traditional file-by-file processing Optimized for small directories and scenarios where batch overhead is not beneficial

func (*TraditionalDirectoryProcessor) ProcessDirectory added in v0.31.2

func (tdp *TraditionalDirectoryProcessor) ProcessDirectory(dirPath string) ([]*item.FileInfo, []error)

ProcessDirectory processes directory using traditional approach optimized for small datasets

Jump to

Keyboard shortcuts

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