Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

co-fs-plus

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-fs-plus - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

74

index.js

@@ -6,3 +6,3 @@ /**

var co = require('co');
var ofs = require('fs'); // Original `fs`
var ofs = require('fs'); // Original `fs`
var fs = require('co-fs');

@@ -13,6 +13,7 @@ var path = require('path');

var resolve = path.resolve;
var dirname = path.dirname;
var realpath = fs.realpath;
var readFile = fs.readFile;
// Original `fs.readdir`
var oreaddir = ofs.readdir;
var oreaddir = ofs.readdir; // Original `fs.readdir`
var ostat = ofs.stat; // Oreaddir `fs.stat`

@@ -65,2 +66,3 @@ /**

done(null, arr);
arr = null;
})();

@@ -116,1 +118,67 @@ });

}
/**
* Expose `mkdirp(path, [mode])`.
*/
fs.mkdirp = mkdirp;
/**
* Recursively mkdir, like `mkdir -p`
*
* Examples:
*
* var res = fs.mkdirp('./web/js/jquery')
*
* @param {String} path
* @param {Number|String} mode
* @return {Object}
* - { path: 'last made directory' }
* - { path: 'last made directory', error: 'mkdir error' }
* @api public
*/
function mkdirp(path, mode, arr) {
if (!mode) {
mode = 0777 & (~process.umask());
} else if (typeof mode === 'string') {
mode = parseInt(mode, 8);
}
if (!arr) arr = [];
path = resolve(path);
function *getPaths(path, arr) {
try {
var stat = yield fs.stat(path);
if (!stat || (stat && !stat.isDirectory())) {
arr.unshift(path);
}
} catch (e) {
arr.unshift(path);
path = dirname(path);
yield getPaths(path, arr);
}
return arr;
}
function *mkp(p) {
while ((p = arr.shift())) {
try {
yield fs.mkdir(p, mode);
path = p;
} catch (e) {
return e;
}
}
}
return function (done) {
co(function *() {
arr = yield getPaths(path, arr);
var err = yield mkp();
var res = { path: path };
if (err) res.error = res;
done(null, res);
})();
};
}

7

package.json
{
"name": "co-fs-plus",
"version": "0.0.2",
"description": "'co-fs' plus, supports `fs.walk` etc.",
"version": "0.0.3",
"description": "'co-fs' plus, supports `fs.walk`, `fs.mkdirp` etc.",
"keywords": [

@@ -12,3 +12,4 @@ "async",

"walk",
"recursive"
"recursive",
"mkdirp"
],

@@ -15,0 +16,0 @@ "homepage": "https://github.com/fundon/co-fs-plus",

# co-fs-plus
`co-fs` plus, supprots `fs.walk(path)` walk a directory tree.
[co-fs](https://github.com/visionmedia/co-fs) plus, supprots `fs.walk` `fs.mkdirp` walk a directory tree.

@@ -24,2 +24,4 @@ ## Installation

}, []);
var res = yield fs.mkdirp('web/js/jquery');
```

@@ -33,4 +35,6 @@

`fs.mkdirp(path, [mode])`
## License
MIT
var co = require('co');
var fs = require('..');
var path = require('path');

@@ -14,1 +15,10 @@ describe('.walk()', function () {

describe('.mkdirp()', function () {
it('should work', function (done) {
co(function *() {
var res = yield fs.mkdirp('test/a/b/c/d/e/f/g')
res.path.should.equal(path.resolve('test/a/b/c/d/e/f/g'));
})(done);
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc