Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added write

  • Loading branch information...
commit 4620214fe7bba2f88723b1d88b329244807ab41b 1 parent ac18243
@tommy351 authored
Showing with 31 additions and 0 deletions.
  1. +31 −0 lib/qfs.js
View
31 lib/qfs.js
@@ -409,10 +409,41 @@ utils.each({
],
write: [
function(data, callback){
+ var fn = [];
+
+ this.each(function(){
+ var _this = this,
+ parent = this.parent();
+
+ fn.push(function(next){
+ parent.exists(function(exist){
+ if (exist){
+ fs.writeFile(_this.path(), data, next);
+ } else {
+ this.parent().mkdir(this.name(), function(){
+ fs.writeFile(_this.path(), data, next);
+ });
+ }
+ });
+ });
+ });
+
+ async.parallel(fn, callback.bind(this));
+ return this;
},
function(data){
+ this.each(function(){
+ var parent = this.parent();
+ if (!parent.exists()){
+ parent.parent().mkdir(parent.name());
+ }
+
+ fs.writeFileSync(this.path(), data);
+ });
+
+ return this;
}
],
read: [
Please sign in to comment.
Something went wrong with that request. Please try again.