Miss any of our Open RFC calls?Watch the recordings here! »

enfsaddins

1.0.1 • Public • Published

Travis Status Appveyor status Codacy Badge Donate

NPM

enfsaddins

Additional methods for node fs module

enfs stands for [E]asy [N]ode [fs]

This module is intended to work as a sub-module of enfspatch

Description

This module will change some behaviors of fs module from node such as creating a queue for opening files when limit is reached, catching the error's and proceeding with the process when possible.

  • This module will change the behaviour of:
    • exists
    • existsSync

Usage

enfsaddins

Valid usage but not the better:

    var fs = require("fs");
    var enfs = require("enfsaddins")(fs);

It's better to use

    var enfs = require("enfspatch");

this will use enfspatch module that implements this module and allows access to all it's methods

Errors

All the methods follows the node culture.

  • Async: Every async method returns an Error in the first callback parameter
  • Sync: Every sync method throws an Error.

Additional Methods

exists

  • exists(path, callback)

Change the natural behaviour of fs.exists to the node culture, it will return an error in the first callback parameter. As exists is deprecated if it cease to exist then exists will use (#existStat) instead

Sync:

  • existsSync(path)
    enfs.exists("/etc/passwd", function(err, itemExists){
        console.log(itemExists ? 'it\'s there' : 'no passwd!');
    });

check: fs.exists

existAccess

  • existAccess(path, [mode], callback)

Will use fs.access to check if the item exists in the file system and if the process as access to the item.

Sync:

  • existAccessSync(path, [mode])
    enfs.existAccess("/etc/passwd", function(err,itemExists){
        console.log(itemExists ? "it\'s there and have access" : "don\'t exist or don\'t have access");
    });

check: fs.access

existStat

existLStat

  • existStat(path,callback)
  • existLStat(path,callback)

Will use fs.stat to check if the item exists in the file system.

Sync:

  • existStatSync(path)
  • existLStatSync(path)
    enfs.existStat("/etc/passwd", function(err,itemExists){
        console.log(itemExists ? "it\'s there" : "don\'t exist");
    });

check: fs.stat

    enfs.existLStat("/etc/passwd", function(err,itemExists){
        console.log(itemExists ? "it\'s there" : "don\'t exist");
    });

check: fs.lstat

existFStat

  • existFStat(fd,callback)

Will use fs.fstat to check if the item exists in the file system.

Sync:

  • existFStatSync(path)
    enfs.existFStat(enfs.openSync("/etc/passwd","r"), function(err,itemExists){
        console.log(itemExists ? "it\'s there" : "don\'t exist");
    });

check: fs.fstat

existStatIsDirectory

existLStatIsDirectory

existFStatIsDirectory

  • existStatIsDirectory(path,callback)
  • existLStatIsDirectory(path,callback)
  • existFStatIsDirectory(path,callback)

Will use fs.stat or fs.lstat or fs.fstat to check if the item exists in the file system, and if it's a directory. This method is just a shortcut to check if an item exists in the file system and it's type

Sync:

  • existStatIsDirectorySync(path)
  • existLStatIsDirectorySync(path)
  • existFStatIsDirectorySync(path)
    enfs.existStatIsDirectory("/etc", function(err,isDirectory,stat){
        console.log(isDirectory ? "it's a directory" : "don\'t exist or it's not a directory.");
    });

check: fs.stat fs.lstat fs.fstat

existStatIsFile

existLStatIsFile

existFStatIsFile

  • existStatIsFile(path,callback)
  • existLStatIsFile(path,callback)
  • existFStatIsFile(path,callback)

Will use fs.stat or fs.lstat or fs.fstat to check if the item exists in the file system, and if it's a file. This method is just a shortcut to check if an item exists in the file system and it's type

Sync:

  • existStatIsFileSync(path)
  • existLStatIsFileSync(path)
  • existFStatIsFileSync(path)
    enfs.existStatIsFile("/etc/passwd", function(err,isFile,stat){
        console.log(isFile ? "it's a file" : "don\'t exist or it's not a file.");
    });

check: fs.stat fs.lstat fs.fstat

existIsSymlink

  • existIsSymlink(path,callback)

Will use fs.lstat to check if the item exists in the file system, and if it's a symbolic link. This method is just a shortcut to check if an item exists in the file system and it's type

Sync:

  • existIsSymlinkSync(path)
    enfs.existIsSymlink("/etc/symlink", function(err,isSymlink,stat){
        console.log(isSymlink ? "it's a symlink" : "don\'t exist or it's not a symlink.");
    });

check: fs.lstat

License

Creative Commons Attribution 4.0 International License

Copyright (c) 2016 Joao Parreira joaofrparreira@gmail.com GitHub

This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit CCA4.

Install

npm i enfsaddins

DownloadsWeekly Downloads

257

Version

1.0.1

License

CC-BY-4.0

Last publish

Collaborators

  • avatar