parallelwalkdir

package
v0.1.149 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package parallelwalkdir provides utilities to traverse a directory structure in parallel, with support for symbolic links and loop detection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Walker)

Option is a function type that allows configuring a Walker.

func WithContext

func WithContext(ctx context.Context) Option

WithContext sets the cancellation context for the walker. When the context is cancelled, the walk stops as soon as possible. If not set, defaults to context.Background() (walk runs to completion).

func WithMaxNumGoroutines

func WithMaxNumGoroutines(i int) Option

WithMaxNumGoroutines allows the consumer to override the default number of parallel goroutines. If i is less than or equal to 0, the default value (2 * runtime.NumCPU()) will be used.

func WithRegexpExclude

func WithRegexpExclude(r *regexp.Regexp) Option

WithRegexpExclude allows the consumer to specify a regular expression. Any path (file or directory) matching this regex will be skipped and not traversed.

func WithRegexpInclude

func WithRegexpInclude(r *regexp.Regexp) Option

WithRegexpInclude allows the consumer to specify a regular expression that the basename of filenames must match. Only files matching the regex will be returned. This option is mutually exclusive with WithValidationFunc.

func WithSizeNotZero

func WithSizeNotZero() Option

WithSizeNotZero allows the consumer to specify that only files with a size greater than 0 bytes should be returned. This option is mutually exclusive with WithValidationFunc.

func WithValidationFunc

func WithValidationFunc(vf WalkDirFunc) Option

WithValidationFunc allows the consumer to specify a custom function to validate if a file should be returned. This option is mutually exclusive with WithRegexpInclude and WithSizeNotZero.

type WalkDirFunc

type WalkDirFunc func(path string, info fs.FileInfo) bool

WalkDirFunc is a function type used for custom file validation. It takes the reported path and file info, and returns true if the file should be included in the results.

type Walker

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

Walker holds the state for a parallel directory traversal. It manages concurrency, tracks visited paths to prevent loops, and returns results via a channel.

func NewWalker

func NewWalker(opts ...Option) *Walker

NewWalker creates and initializes a new Walker with default settings. It accepts a variadic list of Option functions to customize its behavior. Panics if mutually exclusive options are provided.

func (*Walker) ParallelWalk

func (w *Walker) ParallelWalk(rootPath string) (<-chan string, <-chan error)

ParallelWalk starts the directory traversal from the given root path. It returns a read-only channel of strings for file paths, and a read-only channel for any errors encountered. Both channels will be closed once the entire traversal is complete or the context (set via WithContext) is cancelled.

Jump to

Keyboard shortcuts

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