enfsaddins-promise
Additional methods for node fs module with promises
enfs stands for [E]asy [N]ode [fs]
This module is intended to work as a sub-module of enfspatch-promise
Description
This module will add promises to enfsaddins for async methods
All async
methods will have their name + 'P' (ex: exists => existsP)
Usage
enfsaddins-promise
Valid usage but not the better:
const fs = require("fs");
const enfs = require("enfsaddins-promise")(fs);
It's better to use
const enfs = require("enfspatch-promise");
this will use enfspatch-promise 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
- existsP
- existAccessP
- existStatP
- existLStatP
- existFStatP
- existStatIsDirectoryP
- existLStatIsDirectoryP
- existStatIsFileP
- existLStatIsFileP
- existIsSymlinkP
existsp
- existsP(path)
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
enfs.existsP("/etc/passwd").then(function(itemExists){
console.log(itemExists ? 'it\'s there' : 'no passwd!');
});
check: fs.exists
existAccessP
- existAccessP(path, [mode])
Will use fs.access to check if the item exists in the file system and if the process as access to the item.
enfs.existAccessP("/etc/passwd").then(function(itemExists){
console.log(itemExists ? "it\'s there and have access" : "don\'t exist or don\'t have access");
});
check: fs.access
existStatP
existLStatP
- existStatP(path)
- existLStatP(path)
Will use fs.stat to check if the item exists in the file system.
enfs.existStatP("/etc/passwd").then(function(itemExists){
console.log(itemExists ? "it\'s there" : "don\'t exist");
});
check: fs.stat
enfs.existLStatP("/etc/passwd").then(function(itemExists){
console.log(itemExists ? "it\'s there" : "don\'t exist");
});
check: fs.lstat
existFStatP
- existFStatP(fd)
Will use fs.fstat to check if the item exists in the file system.
enfs.existFStatP(fs.openSync("/etc/passwd","r")).then(function(itemExists){
console.log(itemExists ? "it\'s there" : "don\'t exist");
});
check: fs.fstat
existStatIsDirectoryP
existLStatIsDirectoryP
- existStatIsDirectoryP(path)
- existLStatIsDirectoryP(path)
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
enfs.existStatIsDirectoryP("/etc").then(function(isDirectory){
console.log(isDirectory ? "it's a directory" : "don\'t exist or it's not a directory.");
});
check: fs.stat fs.lstat fs.fstat
existStatIsFileP
existLStatIsFileP
- existStatIsFileP(path)
- existLStatIsFileP(path)
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
enfs.existStatIsFileP("/etc/passwd").then(function(isFile){
console.log(isFile ? "it's a file" : "don\'t exist or it's not a file.");
});
check: fs.stat fs.lstat fs.fstat
existIsSymlinkP
- existIsSymlinkP(path)
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
enfs.existIsSymlinkP("/etc/symlink").then(function(isSymlink){
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) 2017 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.