Comparing version 0.1.8 to 0.1.9
@@ -9,2 +9,3 @@ var key, | ||
exports.readFiles = require(path.join(__dirname, 'lib', 'readfiles')); | ||
exports.readFiles = require(path.join(__dirname, 'lib', 'readfiles')); | ||
exports.readFilesStream = require(path.join(__dirname, 'lib', 'readfilesstream')); |
@@ -1,2 +0,2 @@ | ||
var fs = require('fs'), | ||
var fs = require('fs'), | ||
path = require('path'); | ||
@@ -52,3 +52,4 @@ | ||
recursive: true, | ||
encoding: 'utf8' | ||
encoding: 'utf8', | ||
doneOnErr: true | ||
}, options); | ||
@@ -65,3 +66,8 @@ var files = []; | ||
fs.readdir(dir, function(err, list) { | ||
if (err) return done(err); | ||
if (err) { | ||
if (options.doneOnErr === true) { | ||
if (err.code === 'EACCES') return done(); | ||
return done(err); | ||
} | ||
} | ||
var i = 0; | ||
@@ -80,3 +86,3 @@ | ||
fs.stat(file, function(err, stat) { | ||
if (err) return done(err); | ||
if (err && options.doneOnErr === true) return done(err); | ||
if (stat && stat.isDirectory()) { | ||
@@ -87,3 +93,3 @@ if (options.recursive) { | ||
readFiles(file, options, callback, function(err, sfiles) { | ||
if (err) return done(err); | ||
if (err && options.doneOnErr === true) return done(err); | ||
files = files.concat(sfiles); | ||
@@ -93,3 +99,3 @@ next(); | ||
} else next(); | ||
} else { | ||
} else if (stat && stat.isFile()) { | ||
if (options.match && !matches(filename, options.match)) return next(); | ||
@@ -101,3 +107,8 @@ if (options.exclude && matches(filename, options.exclude)) return next(); | ||
fs.readFile(file, options.encoding, function(err, data) { | ||
if (err) return done(err); | ||
if (err) { | ||
if (err.code === 'EACCES') return next(); | ||
if (options.doneOnErr === true) { | ||
return done(err); | ||
} | ||
} | ||
if (callback.length > 3) | ||
@@ -109,2 +120,5 @@ if (options.shortName) callback(null, data, filename, next); | ||
} | ||
else { | ||
next(); | ||
} | ||
}); | ||
@@ -115,2 +129,2 @@ })(); | ||
} | ||
module.exports = readFiles; | ||
module.exports = readFiles; |
{ | ||
"name": "node-dir", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "asynchronous file and directory operations for Node.js", | ||
@@ -22,5 +22,3 @@ "main": "index", | ||
}, | ||
"licenses": [ | ||
"MIT" | ||
], | ||
"license": "MIT", | ||
"keywords": [ | ||
@@ -36,2 +34,5 @@ "node-dir", | ||
], | ||
"dependencies": { | ||
"minimatch": "~2.0.10" | ||
}, | ||
"devDependencies": { | ||
@@ -38,0 +39,0 @@ "mocha": "~1.13.0", |
@@ -18,2 +18,3 @@ [![Build Status](https://secure.travis-ci.org/fshost/node-dir.png)](http://travis-ci.org/fshost/node-dir) | ||
#### readFiles( dir, [options], fileCallback, [finishedCallback] ) | ||
#### readFilesStream( dir, [options], streamCallback, [finishedCallback] ) | ||
Sequentially read the content of each file in a directory, passing the contents to a callback, optionally calling a finished callback when complete. The options and finishedCallback arguments are not required. | ||
@@ -31,2 +32,3 @@ | ||
- sort: sort files in each directory in ascending order (defaults to true) | ||
- doneOnErr: control if done function called on error (defaults to true) | ||
@@ -50,2 +52,20 @@ A reverse sort can also be achieved by setting the sort option to 'reverse', 'desc', or 'descending' string value. | ||
// display contents of huge files in this script's directory | ||
dir.readFilesStream(__dirname, | ||
function(err, stream, next) { | ||
if (err) throw err; | ||
var content = ''; | ||
stream.on('data',function(buffer) { | ||
content += buffer.toString(); | ||
}); | ||
stream.on('end',function() { | ||
console.log('content:', content); | ||
next(); | ||
}); | ||
}, | ||
function(err, files){ | ||
if (err) throw err; | ||
console.log('finished reading files:', files); | ||
}); | ||
// match only filenames with a .txt extension and that don't start with a `.´ | ||
@@ -52,0 +72,0 @@ dir.readFiles(__dirname, { |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
22226
8
368
173
1
7
+ Addedminimatch@~2.0.10
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedminimatch@2.0.10(transitive)