optimizer

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DataFileName is the name of the core data file for an optimizer.
	DataFileName = "rfo-data.json"
)
View Source
const (
	// DefaultParallelLimit is the maximum number of concurrent goroutines that can be used for a
	// single operation.
	DefaultParallelLimit = 8
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FileHash

type FileHash [sha256.Size]byte

FileHash represents the hash of a single file.

func FileHashFromString

func FileHashFromString(hash string) (FileHash, error)

FileHashFromString returns the FileHash for a given string.

func (FileHash) String

func (h FileHash) String() string

String returns the ASCII representation of this hash.

type Optimizer

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

Optimizer optimizes the files in a given directory.

func NewOptimizer

func NewOptimizer(targetPath string, options ...Option) (*Optimizer, error)

NewOptimizer returns a new Optimizer object initialized with the given options.

func (*Optimizer) Clone added in v0.6.3

func (o *Optimizer) Clone() *Optimizer

Clone returns a new Optimizer with the same values as this optimizer.

func (*Optimizer) Copy added in v0.6.0

func (o *Optimizer) Copy(toPath string) (*Optimizer, error)

Copy copies this optimizer to a new path and returns a new corresponding optimizer. This is useful for situations where you want to use another drive as a buffer, etc.

func (*Optimizer) GetDataFilePath added in v0.3.0

func (o *Optimizer) GetDataFilePath() string

GetDataFilePath returns the path to the data file.

func (*Optimizer) Optimize

func (o *Optimizer) Optimize() error

Optimize optimizes files under the given path.

func (*Optimizer) Restore

func (o *Optimizer) Restore() error

Restore restores a path to its pre-optimized state.

type Option

type Option func(*Optimizer)

Option represents an option that can used to configure a Optimizer.

func WithCacheDisabled added in v0.2.0

func WithCacheDisabled() Option

WithCacheDisabled disables caching when generating the file hash table.

func WithExcludes

func WithExcludes(patterns ...*regexp.Regexp) Option

WithExcludes configures Regex patterns for files that should be explicitly excluded from the optimization. NOTE: This option conflicts with WithIncludes.

func WithIncludes

func WithIncludes(patterns ...*regexp.Regexp) Option

WithIncludes configures Regex patterns for files that should be explicitly included in the optimization. If defined, all other files will be excluded. NOTE: This option conflicts with WithExcludes.

func WithLogger added in v0.3.0

func WithLogger(logger *slog.Logger) Option

WithLogger configures the optimizer to output to the given logger.

func WithParallelLimit

func WithParallelLimit(parallelLimit int) Option

WithParallelLimit can be used to configure the maximum number of parallel goroutines to use in any single operation.

type SharedFileMap

type SharedFileMap map[FileHash][]string

SharedFileMap represents a mapping between shared file hashes and their corresponding file paths. This is necessary because the JSON package doesn't know how to handle slices with a fixed size.

func (SharedFileMap) MarshalJSON

func (h SharedFileMap) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler.MarshalJSON(...) interface.

func (*SharedFileMap) UnmarshalJSON

func (h *SharedFileMap) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Marshaler.UnmarshalJSON(...) interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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