-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not traversing subdirectories if some filter functions applied #17
Comments
In general, wouldn't be better to remove/deprecate the use of filter function and instead point users to use piping for filtering? It seems like using filter function in a stream interface can be problematic. Please see my comment above. By removing/deprecating the filter function, users still be able to achieve the filter functionality by using either What are your thoughts on this? |
The only reason to use the This is actually also the reason the filter function causes not traversing subdirectories - they have been filtered out by name before checking to see if they are a directory. I would argue that this is expected behavior and document it specifically. For most use cases (like the one described in this issue) a filter stream is what you actually want. For some specific use optimizations where early termination (especially skipping whole directory trees) is important a piped filter stream will not work and the filter function is exactly what is needed. |
Closing as expected behavior, PR welcome to clarify docs here. |
I was playing with #11 to see if I can find a solution, then I noticed another issue if filter function applied. This is different than #11 that the root directory is part of the result array although filter function is applied. This issue is about not traversing subdirectories at all if some filter functions applied, such as the following example.
Imagine we have
and we want to get only
.md
files. If we use it likethe result array is
['tmp', 'bar.md', 'baz.md']
.So, I checked the code again and based on what I understood it happens because when a filter function is passed, all contents of the root directory pass through the filter function and since
return path.extname(item) === '.md'
fails for all subdirectories , so none of them will be read. Therefore, only items in the root directory itself are returned. Please correct me if I am wrong.Edit
However, if we run the same example using pipe for filtering, everything is just fine. Apparently, the problem only arises when filter function is used.
The text was updated successfully, but these errors were encountered: