Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/dirsum.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ function _summarize(method, hashes) {
return obj;
}

function digest(root, method, callback) {
function digest(root, method, exclude, callback) {
if (!root || typeof(root) !== 'string') {
throw new TypeError('root is required (string)');
}

if (method) {
if (typeof(method) === 'string') {
// NO-OP
if(typeof(exclude) === 'function') {
callback = exclude;
exclude = [];
}else if(typeof(exclude) !== 'object'){
throw new TypeError('exclude must be an object');
}
} else if (typeof(method) === 'function') {
callback = method;
method = 'md5';
exclude = [];
} else {
throw new TypeError('hash must be a string');
}
Expand All @@ -49,12 +57,20 @@ function digest(root, method, callback) {
fs.readdir(root, function(err, files) {
if (err) return callback(err);

exclude.forEach(function(folder){
var index = files.indexOf(folder);
if(index != -1){
files.splice(index, 1);
}
});

if (files.length === 0) {
return callback(undefined, {hash: '', files: {}});
}

var hashed = 0;
files.forEach(function(f) {

var path = root + '/' + f;
fs.stat(path, function(err, stats) {
if (err) return callback(err);
Expand Down