Directory Scan Utilities
scandal provides two utilities:
Scanning a directory for paths matching a set of glob inclusions or exclusions. For example, you want to find a list of paths to search that match a certain pattern, but are not ignored by the
Searching a list of paths for a regex. For example, you have a list of paths, you want to find all instances of
Unsurprisingly, these two things can be combined to scan and search a directory.
It is written to be simple, flexible and efficient. Scandal does the minimum.
We want to provide modules to combine in any way you'd like. Want to scan in one process and search in another? You can do that.
To be clear, scandal is not a CLI. It can be used from the terminal, but in practice it's only used for benchmarking.
scandal provides two main modules:
Usage is simple:
require 'scandal'scanner = '/Users/me/myDopeProject'optionsscanneron 'path-found'consolelogpathscanneron 'finished-scanning'->consolelog'All done!'scannerscan
PathScanner keeps no state. You must consume paths via the 'path-found' event.
['dirname/']will match all paths in direcotry
require 'scandal'searcher =# You can subscribe to a `results-found` eventsearcheron 'results-found'# result will contain all the matches for a single pathconsolelog"Single Path's Results"result# Search a list of pathssearchersearchPaths /text/gi'/Some/path'...consolelog'Done Searching'results# Search a single pathsearchersearchPath /text/gi'/Some/path'consolelog'Done Searching'result
Results from line 10 (1 based) are in the following format.
PathScanner the searcher keeps no state. You need to consume results via the done callbacks or event.
File reading is fast and memory efficient. It reads in 10k chunks and writes over each previous chunk. Small object creation is kept to a minimum during the read to make light use of the GC.
A third object,
PathFilter is available, but intended for use by the
If you dont want to think about combining the
PathSearcher in your own way, a
search is function provided.
require 'scandal'path = '/path/to/search'scanner = pathexcludeVcsIgnores: truesearcher =searcheron 'results-found'# do something rad with the result!name = "Search "consoletime nameconsolelog namesearch /text/igscannersearcher->consoletimeEnd name