Pass file information (name/mode) along to transform functions. #20

Merged
merged 2 commits into from Feb 13, 2013
View
2 lib/ncp.js
@@ -90,7 +90,7 @@ function ncp (source, dest, options, callback) {
var readStream = fs.createReadStream(file.name),
writeStream = fs.createWriteStream(target, { mode: file.mode });
if(transform) {
- transform(readStream, writeStream);
+ transform(readStream, writeStream,file);
} else {
readStream.pipe(writeStream);
}
View
12 test/ncp-test.js
@@ -70,5 +70,17 @@ vows.describe('ncp').addBatch({
}
}
}
+}).addBatch({
+ 'When copying files using transform': {
+ 'it should pass file descriptors along to transform functions': function() {
+ ncp(src, out, {
+ transform: function(read,write,file) {
+ assert.notEqual(file.name, undefined);
+ assert.strictEqual(typeof file.mode,'number');
+ read.pipe(write);
+ }
+ }, function(){});
+ }
+ }
}).export(module);