0.0.1a • Published 11 years ago

node-dir-diff v0.0.1a

Weekly downloads
9
License
-
Repository
-
Last release
11 years ago

node-dir-diff

A directory comparison system using hive-loader/node.js. Compares two or more directories.

The comparisons have three possible "depths":

1) path only -- checks the file/directory paths for added or missing files, but ignores content (comp == 'list'); 2) size -- does a stat, and notes files that are the same name, but different sizes. (comp = 'size') 3) content -- compares file content on a byte level (using the filecompare module). (comp = 'full')

Note that tests that fail a simpler test will not be subjected to higher tests; that is, if a file is not found in all the directories you pass in, the instances of it that do exist will not be compared by size/content.

Usage

To compare two or more directories, simply call

var dd = new ndd.Dir_Diff(
	[
		path.resolve(root, 'test_1'),
		path.resolve(root, 'test_2'),
		path.resolve(root, 'test_3')
	],
	'full'
);

dd.compare(function (err, result) {
if (result.deviation > 0){
	console.log('you have %s deviations!', result.deviation);
	console.log(util.inspect(deviation));
}

});

Any number of directories can be passed in; if the comparison mode is omitted, 'list' is assumed.

The first item in the list is taken as the "normal" directory; this won't affect deviations, but it does explain what the basis is for report elements like "added" or "missing".

Output

The feedback to the callback is a report object:

Most of the report is work product; the deviation and deviations properties are the most significant elements of the report.

where info is

dir-hash is

file-dir-status is [{dir: 'root_dir', devaition: posint, added: 'subpath'... 'subpath' missing: 'subpath' ... 'subpath' } ... {}]

deviation-report is { "type": "string", "info": "string" | info, "variant": "added" | "removed" (optional); }

see the "sample outpuut.json" file in test resources.