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

enfsensure

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enfsensure

Ensure file, folder, link or symlink existence in file system for node fs module

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-83.33%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Build status Codacy Badge Donate

NPM

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 = require("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

  • 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.ensureFile("/path/to/any/file",{ data: "contents", encoding: "utf8" },function(err){
        if(!err){
            console.log("data was written to the file");
        }
    });

Stream

    enfsensure.ensureFile("/path/to/any/file",{ stream: true, streamOptions: { autoClose: true} },function(err, stream){
        if(!err){
            console.log("stream is a WriteStream object.");
        }
    });

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.ensureDir("/path/to/the/new/folder", function(err, path){
        if(!err){
            console.log("directory was created in the path: "+path);
        }
    });
  • 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.ensureLink("/srcPath", "/dstPath", function(err, dstPath){
        //do something
    });
  • 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.ensureSymlink("./foo", "./new-port", "file", function(err, dstPath){
        //do something
    });

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.

Keywords

FAQs

Package last updated on 23 Feb 2016

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

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