enfsensure
Module that add ensure functionality to node fs module
enfs stands for [E]asy [N]ode [fs]
This module is intended to work as a sub-module of enfs
Description
This module will add various method that allows the user to ensure the creation of a file, directory, link or symlink in the file system, if the parent directory of the item to be ensured don't exist it will be automatically created.
- This module will add following methods to node fs module:
- ensureFile
- ensureFileSync
- ensureDir
- ensureDirSync
- ensureLink
- ensureLinkSync
- ensureSymlink
- ensureSymlinkSync
Usage
enfsensure
var enfsensure = ;
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
- ensureFile
- ensureFileSync
- ensureDir
- ensureDirSync
- ensureLink
- ensureLinkSync
- ensureSymlink
- ensureSymlinkSync
ensureFile
- ensureFile(path, [options], callback)
Ensures the file existence in the file system, if the file don't exist it will be created.
[options]:
- fs (Object): an alternative fs module to use (default will be enfspatch)
- mode (String or Number): the mode to set to the file, if the file already exists and have a different mode it will be change to the new mode
- data (String): Data that will be written to the file, if it already exists the data will be appended if append flag is true.
- append (Boolean): if true data will be appended to the file (Default: false)
- encoding (String): specify the file encoding
- dirMode (String or Number): the mode that will be set to the parent directory
- stream (Boolean): if true this method will return a WriteStream to the ensured file
- streamOptions (Object): Options that will be passed to the WriteStream createWriteStream()
Sync: * ensureFileSync(path,[options])
enfsensure;
Stream
enfsensure;
ensureDir
- ensureDir(path, [options], callback)
Ensure directory existence in the file system, if directory don't exist it will be created
[options]:
- fs (Object): an alternative fs module to use (default will be enfspatch)
- mode (String or Number): the mode to set to the directory, if the directory already exists and is different then it will be changed to the new mode
Sync: * ensureDirSync(path,[options])
enfsensure;
ensureLink
- ensureLink(srcPath, dstPath, [options], callback)
Ensure link creation in the file system. link
[options]:
- fs (Object): an alternative fs module to use (default will be enfspatch)
Sync: * ensureLinkSync(srcPath, dstPath, [options])
enfsensure;
ensureSymlink
- ensureSymlink(target, path, [options], callback)
Ensure symlink creation in the file system. symlink
[options]:
- fs (Object): an alternative fs module to use (default will be enfspatch)
- type (String): symlink type (Default: file)
Sync: * ensureSymlinkSync(path,[options])
enfsensure;
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 CC-BY-4.0.