Comparing version 0.1.2 to 1.0.0
62
cprf.js
@@ -5,13 +5,9 @@ var fs = require('fs'); | ||
function mkdir (dir, done) { | ||
fs.exists(dir, function (exists) { | ||
if (exists) return done(); | ||
fs.mkdir(dir, function (err) { | ||
if (err) return done(new Error(err)); | ||
done(); | ||
}); | ||
}); | ||
} | ||
var DEFAULT_LIMIT = 24; | ||
function copy (src, dest, done) { | ||
module.exports = copy; | ||
function copy (src, dest, done, limit) { | ||
limit = limit || DEFAULT_LIMIT; | ||
fs.lstat(src, function (err, stats) { | ||
@@ -25,7 +21,4 @@ if (err) return done(new Error(err)); | ||
if (err) return done(new Error(err)); | ||
async.each(files, function(filename, done) { | ||
copy( | ||
path.join(src, filename), | ||
path.join(dest, filename), | ||
done); | ||
async.eachLimit(files, limit, function (file, done) { | ||
copy(path.join(src, file), path.join(dest, file), done, limit); | ||
}, done); | ||
@@ -45,16 +38,33 @@ }); | ||
var fin = fs.createReadStream(src); | ||
var fout = fs.createWriteStream(dest); | ||
copyFile(src, dest, function (err) { | ||
if (err) return done(err); | ||
fs.chmod(dest, stats.mode, done); | ||
}); | ||
fin.on('end', function () { | ||
fs.chmod(dest, stats.mode, function (err) { | ||
if (err) return done(new Error(err)); | ||
done(); | ||
}); | ||
}); | ||
fin.on('error', done); | ||
fin.pipe(fout); | ||
}); | ||
} | ||
module.exports = copy; | ||
function mkdir (dir, done) { | ||
fs.exists(dir, function (exists) { | ||
return exists ? done() : fs.mkdir(dir, done); | ||
}); | ||
} | ||
function copyFile (src, dest, done) { | ||
var doneCalled = false; | ||
var fin = fs.createReadStream(src); | ||
fin.on('error', finish); | ||
var fout = fs.createWriteStream(dest); | ||
fout.on('error', finish); | ||
fout.on('close', finish); | ||
fin.pipe(fout); | ||
function finish (err) { | ||
if (doneCalled) return; | ||
doneCalled = true; | ||
done(err); | ||
} | ||
} |
{ | ||
"name": "cprf", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"description": "Recursively copy files and directories", | ||
@@ -11,4 +11,9 @@ "main": "cprf.js", | ||
"type": "git", | ||
"url": "https://www.github.com/lxe/cprf" | ||
"url": "https://github.com/lxe/cprf.git" | ||
}, | ||
"homepage": "https://github.com/lxe/cprf", | ||
"bugs": { | ||
"url": "https://github.com/lxe/cprf/issues", | ||
"email": "lxe@lxe.co" | ||
}, | ||
"keywords": [ | ||
@@ -24,4 +29,4 @@ "copy", | ||
"dependencies": { | ||
"async": "0.9.0", | ||
"rimraf": "2.2.8" | ||
"async": "~0.9.x", | ||
"rimraf": "~2.2.x" | ||
}, | ||
@@ -31,2 +36,2 @@ "devDependencies": { | ||
} | ||
} | ||
} |
@@ -13,2 +13,3 @@ # cprf | ||
- Fully asynchronous | ||
- Limits file descriptors to 24 (per invocation) | ||
- Attempts to call back with meaningful errors | ||
@@ -32,3 +33,5 @@ - Tests! | ||
} | ||
}); | ||
}, 24); | ||
/// where '24' is the asynchronous concurrency limit. | ||
``` | ||
@@ -38,2 +41,6 @@ | ||
#### 1.0.0 | ||
- Add default/adjustable concurrency limit | ||
#### 0.1.2 | ||
@@ -40,0 +47,0 @@ |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
7089
129
1
0
59
+ Addedasync@0.9.2(transitive)
- Removedasync@0.9.0(transitive)
Updatedasync@~0.9.x
Updatedrimraf@~2.2.x