Comparing version 0.1.3 to 0.1.4
@@ -9,3 +9,3 @@ /** | ||
* | ||
* @version 0.1.3 | ||
* @version 0.1.4 | ||
*/ | ||
@@ -29,2 +29,3 @@ | ||
makeDir = promisify(fs.mkdir), | ||
remove = promisify(fs.unlink), | ||
removeDir = promisify(fs.rmdir), | ||
@@ -61,7 +62,23 @@ undef; | ||
/** | ||
* Remove file by given path | ||
* @param {String} path | ||
* Remove given path | ||
* @param {String} pathToRemove | ||
* @returns {Vow.promise} | ||
*/ | ||
remove : promisify(fs.unlink), | ||
remove : function(pathToRemove) { | ||
var _this = this; | ||
return _this.isDir(pathToRemove).then(function(isDir) { | ||
return isDir? | ||
_this.listDir(pathToRemove) | ||
.then(function(list) { | ||
return list.length && Vow.all( | ||
list.map(function(file) { | ||
return _this.remove(path.join(pathToRemove, file)); | ||
})); | ||
}) | ||
.then(function() { | ||
return removeDir(pathToRemove); | ||
}) : | ||
remove(pathToRemove); | ||
}); | ||
}, | ||
@@ -75,23 +92,35 @@ /** | ||
copy : function(sourcePath, targetPath) { | ||
var promise = Vow.promise(), | ||
sourceStream = fs.createReadStream(sourcePath), | ||
targetStream = fs.createWriteStream(targetPath), | ||
errFn = function(err) { | ||
promise.reject(err); | ||
}; | ||
return this.isFile(sourcePath).then(function(isFile) { | ||
if(!isFile) { | ||
var err = Error(); | ||
err.errno = 28; | ||
err.code = 'EISDIR'; | ||
err.path = sourcePath; | ||
throw err; | ||
} | ||
sourceStream.on('error', errFn); | ||
targetStream | ||
.on('error', errFn) | ||
.on('close', function() { | ||
promise.fulfill(); | ||
}); | ||
var promise = Vow.promise(), | ||
sourceStream = fs.createReadStream(sourcePath), | ||
errFn = function(err) { | ||
promise.reject(err); | ||
}; | ||
sourceStream.pipe(targetStream); | ||
sourceStream | ||
.on('error', errFn) | ||
.on('open', function() { | ||
var targetStream = fs.createWriteStream(targetPath); | ||
sourceStream.pipe( | ||
targetStream | ||
.on('error', errFn) | ||
.on('close', function() { | ||
promise.fulfill(); | ||
})); | ||
}); | ||
return promise; | ||
return promise; | ||
}); | ||
}, | ||
/** | ||
* Move file from sourcePath to targetPath | ||
* Move from sourcePath to targetPath | ||
* @param {String} sourcePath | ||
@@ -237,27 +266,3 @@ * @param {String} targetPath | ||
}); | ||
}, | ||
/** | ||
* Remove a directory at the given path, recursively removing any contained files and directories | ||
* @param {String} dirPath | ||
* @returns {Vow.promise} | ||
*/ | ||
removeDir : function(dirPath) { | ||
var _this = this; | ||
return _this.listDir(dirPath) | ||
.then(function(list) { | ||
return list.length && Vow.all( | ||
list.map(function(file) { | ||
var fullPath = path.join(dirPath, file); | ||
return _this.isDir(fullPath).then(function(isDir) { | ||
return isDir? | ||
_this.removeDir(fullPath) : | ||
_this.remove(fullPath); | ||
}); | ||
})); | ||
}) | ||
.then(function() { | ||
return removeDir(dirPath); | ||
}); | ||
} | ||
}; |
{ | ||
"name" : "vow-fs", | ||
"version" : "0.1.3", | ||
"version" : "0.1.4", | ||
"description" : "File I/O by Vow", | ||
@@ -21,6 +21,11 @@ "homepage" : "https://github.com/dfilatov/vow-fs", | ||
"devDependencies": { | ||
"vow" : "0.1.x" | ||
"vow" : "0.1.x", | ||
"nodeunit" : "", | ||
"istanbul" : "" | ||
}, | ||
"main" : "lib/fs", | ||
"engines" : { "node" : ">= 0.6.0" } | ||
"engines" : { "node" : ">= 0.6.0" }, | ||
"scripts" : { | ||
"test" : "./node_modules/istanbul/lib/cli.js test test/runner.js" | ||
} | ||
} |
@@ -36,3 +36,2 @@ Vow-fs | ||
####listDir(path)#### | ||
####makeDir(path, [mode])#### | ||
####removeDir(path)#### | ||
####makeDir(path, [mode], [failIfExist=false])#### |
var fs = require('./lib/fs'), | ||
path = require('path'); | ||
fs.makeDir('package.json').then(function(ex) { | ||
fs.remove('test/test-dir').then(function(ex) { | ||
console.log('!'); | ||
@@ -6,0 +6,0 @@ }, function(err) { |
Sorry, the diff of this file is not supported yet
16568
9
459
3
37
5