Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added read

  • Loading branch information...
commit 5fb8e9e0f727848874f92dbe278d2feec19a430f 1 parent f1ec1e7
@tommy351 authored
Showing with 25 additions and 2 deletions.
  1. +25 −2 lib/qfs.js
View
27 lib/qfs.js
@@ -416,11 +416,34 @@ utils.each({
}
],
read: [
- function(callback){
+ function(encoding, callback){
+ if (utils.isFunction(encoding)){
+ callback = encoding;
+ encoding = 'utf8';
+ }
+ this.stat(function(err, stat){
+ if (err) return callback(err);
+ if (stat.isFile()){
+ fs.readFile(this.path(), encoding, callback.bind(this));
+ return this;
+ } else {
+ return this.children(callback);
+ }
+ })
},
- function(){
+ function(encoding){
+ if (utils.isUndefined(encoding)){
+ encoding = 'utf8';
+ }
+ var stat = this.stat();
+
+ if (stat.isFile()){
+ return fs.readFileSync(this.path(), encoding);
+ } else {
+ return this.children();
+ }
}
],
append: [
Please sign in to comment.
Something went wrong with that request. Please try again.