node-readfiles
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -34,2 +34,3 @@ var fs = require('fs'); | ||
options = options || {}; | ||
callback = typeof callback === 'function' ? callback : null; | ||
doneCallback = doneCallback || function () {}; | ||
@@ -71,4 +72,4 @@ | ||
if (err) { | ||
if (typeof callback === 'function') { | ||
callback(err, relFilename, null); | ||
if (callback && callback(err, relFilename, null, stat, next) === false && !err) { | ||
return; | ||
} | ||
@@ -111,4 +112,4 @@ if (options.doneOnError !== false) { | ||
if (options.readContents === false) { | ||
if (typeof callback === 'function') { | ||
callback(null, outputName, null, stat); | ||
if (callback && callback(null, outputName, null, stat, next) === false) { | ||
return; | ||
} | ||
@@ -120,4 +121,6 @@ return next(); | ||
fs.readFile(fullpath, options.encoding || 'utf8', function (err, content) { | ||
if (typeof callback === 'function') { | ||
callback(err, outputName, content, stat); | ||
// call "callback" | ||
if (callback && callback(err, outputName, content, stat, next) === false && !err) { | ||
return; | ||
} | ||
@@ -124,0 +127,0 @@ if (err && options.doneOnError !== false) { |
{ | ||
"name": "node-readfiles", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "A lightweight Node.js module to recursively read files in a directory", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -39,6 +39,9 @@ # node-readfiles | ||
### callback(err, filename, content, stat) | ||
### callback(err, filename, content, stat, next) | ||
The callback function that is triggered everytime a file is read. If there's an error while reading the file the `err` parameter will contain the error that occured, otherwise the if `readContents` is true, the `contents` parameter will be populated with the contents of the file encoded using the `encoding` option. | ||
The optional callback function is triggered everytime a file is found. If there's an error while reading the file the `err` parameter will contain the error that occured, When `readContents` is true, the `contents` parameter will be populated with the contents of the file encoded using the `encoding` option. For convenience the `stat` result object is passed to the callback for you to use. | ||
If you're doing a long operation and want to pause on every file, have the callback return `false`, will cause `readfiles` to pause until you call `next`. See bellow for an example. | ||
<span id="read-files">[1]</span> The `contents` parameter will be `null` when the `readContents` option is `false`. | ||
@@ -150,2 +153,18 @@ | ||
This example waits for async calls to occur on every file. | ||
```javascript | ||
var readfiles = require('readfiles'); | ||
readfiles('/path/to/dir/', function (err, content, filename, stat, next) { | ||
if (err) throw err; | ||
setTimeout(function () { | ||
console.log('File ' + filename); | ||
next(); | ||
}, 3000); | ||
return false; | ||
}); | ||
``` | ||
A simple example that works like `find` | ||
@@ -152,0 +171,0 @@ |
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
28279
611
202