Skip to content

This library allows you to find the files containing a particular string. It returns a channel, this way as soon as a file is found, the consumer can start doing any other process with it.

Notifications You must be signed in to change notification settings

tonisanta/Filefinder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Filefinder

This library allows you to find the files containing a particular string. It returns a channel, as the traverse of the directories is done concurrently, as soon as a file is found, it's inserted in the channel.

func ExampleFindFiles() {
	outChan, err := FindFiles(testFS, "Hello")
	if err != nil {
		log.Fatalf("Error: %s", err)
	}

	for file := range outChan {
		fmt.Println(file)
	}

	// Keep in mind that the order is not deterministic
	// Output: greeting.txt
	// subdirectory\greeting2.txt
	// subdirectory\another\greeting3.txt
}

Benchmarking

The standard library provides a function to traverse a directory (WalkDir), and you can provide a custom function to run for each entry, however, this traverse is done in a single thread.

On the other hand, this function creates a goroutine per each entry, this way multiple files can be checked at the same time. This way, as soon as a file is found, the consumer can start doing any other process with it.

Function Mean execution time Bytes allocated Number allocations
BenchmarkWalkDirStdLib 131338412 ns/op 526225622 B/op 1032780 allocs/op
BenchmarkWalkDir 55356895 ns/op 410276759 B/op 1017930 allocs/op

About

This library allows you to find the files containing a particular string. It returns a channel, this way as soon as a file is found, the consumer can start doing any other process with it.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages