Skip to content

Commit

Permalink
lib/walk: extracted out into module klaw
Browse files Browse the repository at this point in the history
  • Loading branch information
jprichardson committed Oct 25, 2015
1 parent 4c2af0e commit cae574f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 104 deletions.
39 changes: 4 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ fs.removeSync('/home/jprichardson') //I just deleted my entire HOME directory.

### walk()

**walk(dir)**
**walk(dir, [streamOptions])**

The function `walk()` from the module [`klaw`](https://github.com/jprichardson/node-klaw).

Returns a [Readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable) that iterates
through every file and directory starting with `dir` as the root. Every `read()` or `data` event
Expand Down Expand Up @@ -436,40 +438,7 @@ fse.walk(TEST_DIR)
If you're not sure of the differences on Node.js streams 1, 2, 3 then I'd
recommend this resource as a good starting point: https://strongloop.com/strongblog/whats-new-io-js-beta-streams3/.

#### Filtering the file walker stream

On many occasions you may want to filter files based upon size, extension, etc.
You should use the module [`through2`](https://www.npmjs.com/package/through2) to easily
accomplish this.

Example (skipping directories):

first:

npm i --save through2


```js
var fs = require('fs-extra')
var through2 = require('through2')

var excludeDirFilter = through2.obj(function (item, enc, next) {
if (!item.stat.isDirectory()) this.push(item)
next()
})

var items = [] // files, directories, symlinks, etc
fse.walk(TEST_DIR)
.pipe(excludeDirFilter)
.on('data', function (item) {
items.push(item.path)
})
.on('end', function () {
console.dir(items) // => [ ... array of files without directories]
})

```

**See [`klaw` documentation](https://github.com/jprichardson/node-klaw) for more detailed usage.**


### writeJson(file, object, [options], callback)
Expand Down
8 changes: 2 additions & 6 deletions lib/walk/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
var Walker = require('./walker')

function walk (path) {
return new Walker(path)// .start()
}
var klaw = require('klaw')

module.exports = {
walk: walk
walk: klaw
}
63 changes: 0 additions & 63 deletions lib/walk/walker.js

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dependencies": {
"graceful-fs": "^4.1.2",
"jsonfile": "^2.1.0",
"klaw": "^1.0.0",
"path-is-absolute": "^1.0.0",
"rimraf": "^2.2.8"
},
Expand Down

0 comments on commit cae574f

Please sign in to comment.