Permalink
Browse files

added append

  • Loading branch information...
1 parent 5fb8e9e commit 3af713658497e218c8240045f6716084c99b2908 @tommy351 committed Sep 3, 2012
Showing with 38 additions and 0 deletions.
  1. +38 −0 lib/qfs.js
View
@@ -448,10 +448,48 @@ utils.each({
],
append: [
function(data, callback){
+ var fn = [];
+
+ this.each(function(){
+ var _this = this;
+
+ fn.push(function(next){
+ var stat = _this.stat();
+
+ if (stat.isFile()){
+ if (_this.exists()){
+ fs.appendFile(this.path(), data, next);
+ } else {
+ _this.write(data, next);
+ }
+ } else {
+ var newFile = qfs(this.path() + sep + data);
+ newFile.write('', next);
+ }
+ });
+ });
+ async.parallel(fn, callback);
+
+ return this;
},
function(data){
+ this.each(function(){
+ var stat = this.stat();
+ if (stat.isFile()){
+ if (this.exists()){
+ fs.appendFileSync(this.path(), data);
+ } else {
+ this.write(data);
+ }
+ } else {
+ var newFile = qfs(this.path() + sep + data);
+ newFile.write('');
+ }
+ });
+
+ return this;
}
],
content: [

0 comments on commit 3af7136

Please sign in to comment.