Comparing version 0.1.1 to 0.2.0
{ | ||
"name": "walkdir", | ||
"description": "Find files simply. Walks a directory tree emitting events based on what it finds. Presents a familiar callback/emitter/a+sync interface. Walk a tree of any depth.", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"author": "Ryan Day <soldair@gmail.com>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -45,3 +45,2 @@ [![Build Status](https://secure.travis-ci.org/soldair/node-walkdir.png)](http://travis-ci.org/soldair/node-walkdir) | ||
## install | ||
@@ -62,11 +61,44 @@ | ||
```js | ||
{ | ||
"follow_symlinks": false, // default is off | ||
"no_recurse": false, // only recurse one level deep | ||
"max_depth": undefined // only recurse down to max_depth. if you need more than no_recurse | ||
"track_inodes": true // on windows or with hardlinks some files are not emitted due to inode collision. | ||
// ^ should be used with max_depth to prevent infinite loop | ||
} | ||
``` | ||
```js | ||
{ | ||
/** | ||
* follow symlinks. default FALSE | ||
*/ | ||
"follow_symlinks"?: boolean, | ||
/** | ||
* only go one level deep. convenience param. | ||
*/ | ||
"no_recurse"?: boolean, | ||
/** | ||
* only travel to max depth. emits an error if hit. | ||
*/ | ||
"max_depth"?: number, | ||
/** | ||
* on filesystems where inodes are not unique like windows (or perhaps hardlinks) some files may not be emitted due to inode collision. | ||
* turning off this behavior may be required but at the same time may lead to hitting max_depth via link loop. | ||
*/ | ||
"track_inodes"?: boolean; | ||
/** | ||
* make this syncronous. the same as calling walkdir.sync | ||
*/ | ||
"sync"?:boolean, | ||
/** | ||
* return an object of {path:stat} instead of just the resolved path names | ||
*/ | ||
"return_object"?: boolean, | ||
/** | ||
* dont build up an internal list or object of all of the paths. this can be an important optimization for listing HUGE trees. | ||
*/ | ||
"no_return"?: boolean, | ||
/** | ||
* filter. filter an array of paths from readdir | ||
*/ | ||
"filter"?:(directory:string,files:string[])=>string[]|Promise<string[]>, | ||
/** | ||
* pass in a custom fs object like gracfeful-fs | ||
* needs stat, lstat, readdir, readlink and sync verisons if you use sync:true | ||
*/ | ||
"fs"?:any | ||
} | ||
``` | ||
@@ -93,33 +125,33 @@ - walkdir.sync/walkdir.async only | ||
###path | ||
### path | ||
fired for everything | ||
###file | ||
### file | ||
fired only for regular files | ||
###directory | ||
### directory | ||
fired only for directories | ||
###link | ||
### link | ||
fired when a symbolic link is found | ||
###end | ||
### end | ||
fired when the entire tree has been read and emitted. | ||
###socket | ||
### socket | ||
fired when a socket descriptor is found | ||
###fifo | ||
### fifo | ||
fired when a fifo is found | ||
###characterdevice | ||
### characterdevice | ||
fired when a character device is found | ||
###blockdevice | ||
### blockdevice | ||
fired when a block device is found | ||
###targetdirectory | ||
### targetdirectory | ||
fired for the stat of the path you provided as the first argument. is is only fired if it is a directory. | ||
###empty | ||
### empty | ||
fired for empty directory | ||
@@ -130,6 +162,6 @@ | ||
###error | ||
### error | ||
if the target path cannot be read an error event is emitted. this is the only failure case. | ||
###fail | ||
### fail | ||
when stat or read fails on a path somewhere in the walk and it is not your target path you get a fail event instead of error. | ||
@@ -136,0 +168,0 @@ This is handy if you want to find places you dont have access too. |
@@ -71,2 +71,6 @@ import { EventEmitter } from "events"; | ||
"no_return"?: boolean, // if true null will be returned and no array or object will be created with found paths. useful for large listings | ||
/** | ||
* filter. filter an array of paths from readdir | ||
*/ | ||
"filter"?:(directory:string,files:string[])=>string[]|Promise<string[]>, | ||
} | ||
@@ -73,0 +77,0 @@ |
@@ -175,2 +175,21 @@ var EventEmitter = require('events').EventEmitter, | ||
if(path == sep) path=''; | ||
if(options.filter){ | ||
var res = options.filter(path,files) | ||
if(!res){ | ||
throw new Error('option.filter funtion must return a array of strings or a promise') | ||
} | ||
// support filters that return a promise | ||
if(res.then){ | ||
job(1) | ||
res.then((files)=>{ | ||
job(-1) | ||
for(var i=0,j=files.length;i<j;i++){ | ||
statter(path+sep+files[i],false,(depth||0)+1); | ||
} | ||
}) | ||
return; | ||
} | ||
//filtered files. | ||
files = res | ||
} | ||
for(var i=0,j=files.length;i<j;i++){ | ||
@@ -177,0 +196,0 @@ statter(path+sep+files[i],false,(depth||0)+1); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39808
41
929
215