merged with master repo

This commit is contained in:
refaelos 2012-11-09 14:18:33 +02:00
commit fcc6760b11
5 changed files with 19 additions and 8 deletions

View file

@ -183,8 +183,12 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
var files = fs.readdirSync(sourceDir); var files = fs.readdirSync(sourceDir);
for(var i = 0; i < files.length; i++) { for(var i = 0; i < files.length; i++) {
// ignores all files or directories which match the RegExp in opts.filter
if(!opts.whitelist && opts.filter && files[i].match(opts.filter)) continue;
// if opts.whitelist is true every file or directory which doesn't match opts.filter will be ignored
if(opts.whitelist && opts.filter && !files[i].match(opts.filter)) continue;
if (opts.excludeHiddenUnix && /^\./.test(files[i])) continue; if (opts.excludeHiddenUnix && /^\./.test(files[i])) continue;
var currFile = fs.lstatSync(sourceDir + "/" + files[i]); var currFile = fs.lstatSync(sourceDir + "/" + files[i]);
var fCopyFile = function(srcFile, destFile) { var fCopyFile = function(srcFile, destFile) {
@ -289,7 +293,7 @@ exports.rmdirRecursive = function rmdirRecursive(dir, clbk){
return fs.rmdir(dir, clbk); return fs.rmdir(dir, clbk);
var file = dir+'/'+filename; var file = dir+'/'+filename;
fs.stat(file, function(err, stat){ fs.lstat(file, function(err, stat){
if (err) return clbk(err); if (err) return clbk(err);
if (stat.isDirectory()) if (stat.isDirectory())
rmdirRecursive(file, rmFile); rmdirRecursive(file, rmFile);
@ -384,6 +388,10 @@ exports.LineReader = function(filename, bufferSize) {
}; };
exports.LineReader.prototype = { exports.LineReader.prototype = {
close: function() {
return fs.closeSync(this.fd);
},
getBufferAndSetCurrentPosition: function(position) { getBufferAndSetCurrentPosition: function(position) {
var res = fs.readSync(this.fd, this.bufferSize, position, "ascii"); var res = fs.readSync(this.fd, this.bufferSize, position, "ascii");

View file

@ -1,7 +1,7 @@
{ {
"name": "wrench", "name": "wrench",
"description": "Recursive filesystem (and other) operations that Node *should* have.", "description": "Recursive filesystem (and other) operations that Node *should* have.",
"version": "1.3.9", "version": "1.4.0",
"author": "Ryan McGrath <ryan@venodesigns.net>", "author": "Ryan McGrath <ryan@venodesigns.net>",
"repository": { "repository": {

View file

@ -45,6 +45,10 @@ var f = new wrench.LineReader('x.txt');
while(f.hasNextLine()) { while(f.hasNextLine()) {
util.puts(x.getNextLine()); util.puts(x.getNextLine());
} }
// Note: You will need to close that above line reader at some point, otherwise
// you will run into a "too many open files" error. f.close() or fs.closeSync(f.fd) are
// your friends, as only you know when it is safe to close.
``` ```
### Asynchronous operations ### Asynchronous operations
@ -54,7 +58,6 @@ var files = [];
wrench.readdirRecursive('my_directory_name', function(error, curFiles) { wrench.readdirRecursive('my_directory_name', function(error, curFiles) {
// curFiles is what you want // curFiles is what you want
}); });
``` ```
Questions, comments? Hit me up. (ryan [at] venodesigns.net | http://twitter.com/ryanmcgrath) Questions, comments? Hit me up. (ryan [at] venodesigns.net | http://twitter.com/ryanmcgrath)

View file

@ -7,11 +7,11 @@ module.exports = testCase({
test_mkdirSyncRecursive: function(test) { test_mkdirSyncRecursive: function(test) {
var dir = __dirname + '/_tmp/foo/bar'; var dir = __dirname + '/_tmp/foo/bar';
test.equals(path.existsSync(dir), false, 'Dir shouldn\'t exist - clean it up manually?'); test.equals(fs.existsSync(dir), false, 'Dir shouldn\'t exist - clean it up manually?');
wrench.mkdirSyncRecursive(dir, 0777); wrench.mkdirSyncRecursive(dir, 0777);
test.equals(path.existsSync(dir), true, 'Dir should exist now'); test.equals(fs.existsSync(dir), true, 'Dir should exist now');
// clean up // clean up
while (dir != __dirname) { while (dir != __dirname) {

View file

@ -23,7 +23,7 @@ module.exports = testCase({
test_readdirSyncRecursive: function(test) { test_readdirSyncRecursive: function(test) {
var dir = path.join(__dirname, 'readdir'); var dir = path.join(__dirname, 'readdir');
test.ok(path.existsSync(dir), 'Folders should exist'); test.ok(fs.existsSync(dir), 'Folders should exist');
var files = wrench.readdirSyncRecursive(dir); var files = wrench.readdirSyncRecursive(dir);
@ -33,7 +33,7 @@ module.exports = testCase({
test_readdirRecursive: function(test) { test_readdirRecursive: function(test) {
var dir = path.join(__dirname, 'readdir'); var dir = path.join(__dirname, 'readdir');
test.ok(path.existsSync(dir), 'Folders should exist'); test.ok(fs.existsSync(dir), 'Folders should exist');
var allFiles = []; var allFiles = [];