New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

fs-tools

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-tools

fs helper utilities (walk, copy, mkdir -p)


Version published
Weekly downloads
1.2K
decreased by-25.19%
Maintainers
1
Weekly downloads
 
Created

fs-tools

Useful file utitiles. See API Documentation for detailed info.


walk(path, [pattern,] iterator[, callback])

Recurcively scan files by regex pattern & apply iterator to each. Iterator applyed only to files, not to directories.

fstools.walk('/home/nodeca', '\.yml$', function (path, stats, callback) {
  fs.readFile(path, 'utf-8', funtion (err, str) {
    if (err) {
      callback(err);
      return;
    }

    console.log(str);
    callback();
  });
}, function (err) {
  if (err) {
    console.error(err);
  }

  console.log('Done!');
});

remove(path, callback)

Recursively delete directory with all content.

fstools.remove('/home/nodeca/trash', function (err) {
  if (err) {
    console.log("U can't touch that");
    console.err(err);
    process.exit(1);
  } else {
    console.log("It's Hammer time");
    process.exit(0);
  }
});

mkdir(path, mode = '0755', callback)

Recursively make path.

fstools.mkdir('/home/nodeca/media/xxx', function (err) {
  if (err) {
    console.log("Can't' create directory");
    console.err(err);
    process.exit(1);
  } else {
    console.log("We can now store some romantic movies here");
    process.exit(0);
  }
});

copy(src, dst, callback)

Copy file. Not optimized for big sourses (read all to memory at once).

var src = '/home/nodeca/secrets.yml',
    dst = '/home/nodeca/very/deep/secrets/main.yml';

fstools.copy(src, dst, function (err) {
  if (err) {
    console.log("Failed to copy " + src + " into " + dst);
    console.err(err);
    process.exit(1);
  } else {
    console.log("Fone!");
    process.exit(0);
  }
});

License

View the LICENSE file (MIT).

Keywords

FAQs

Package last updated on 24 Nov 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts