npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fs-promise2

v1.0.2

Published

fs module methode as promises with nice error handler

Downloads

19

Readme

fs-promise2 - fs module methode as promises with nice error handler

fs module methode as promises with nice error handler. All fs-promise2 methods take the same argument as their namesake methode of fs module *https://nodejs.org/api/fs.html *http://sidsonaidson.github.io/fs-promise2/. *https://www.npmjs.com/package/fs-promise2

  • Tags: node.js, fs

##Installation

npm install fs-promise2

##Usage


let FileManager = require('fs-promise2');

let File = FileManager.File;
let ExceptionManager = FileManager.ExceptionManager;

File.appendFile('hello.txt')
    .then((buffer) => {
        console.log(`Data added to file`, buffer);
    })
    .catch(ExceptionManager.ArgumentNullException, (e) => {
        console.log(`Null args passed to function`, e);
    })
    .catch(ExceptionManager.ArgumentException, (e) => {
        console.log(`illegal args passed to function`, e);
    })
    .catch(ExceptionManager.PathTooLongException, (e) => {
        console.log(`path exceeds the system-defined maximum length.`, e);
    })
    .catch(ExceptionManager.NotSupportedException, (e) => {
        console.log(`path is in an invalid format.`, e);
    })
    .catch(ExceptionManager.UnauthorizedAccessException, (e) => {
        console.log(`no rigth on file`, e);
    })
    .catch(ExceptionManager.IOException, (e) => {
        console.log(`io problem`, e);
    })
    .catch((e) => {
        console.log(e);
    });

##API ##Already Availaible method

fs.access,
fs.appendFile,
fs.chmod,
fs.chown,
fs.close,
fs.createReadStream,
fs.createWriteStream,
fs.exist,
fs.fchmod,
fs.fchown,
fs.fdatasync,
fs.fstat, fs.fsync,
fs.ftruncate,
fs.futimes,
fs.lchmod,
fs.lchown,
fs.link,
fs.lstat,
fs.mkdir,
fs.mkdtemp,
fs.open,
fs.read,
fs.readdir,
fs.readFile,
fs.readlink,
fs.realpath,
fs.rename,
fs.stat,
fs.writeFile,
fs.write,
fs.unwatchFile
fs.unlink,
fs.truncate
// next soon

fs.write exist in 3 version in fs-promise2: File.write, File.WriteV002, File.writeV0115; https://nodejs.org/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback and https://nodejs.org/api/fs.html#fs_fs_write_fd_string_position_encoding_callback

File.write use V002

##Exception

/**
 * Illegal argument type passed to function
 * @type {Error}
 */
ArgumentException
/**
 * The file or dir specified by path was not found.
 * @type {Error}
 */
DirectoryOrFileNotFoundException
/**
 * null args passed to function while expected not null
 * @type {Error}
 */
ArgumentNullException
/**
 * the directory doesn’t exist or it is on an unmapped drive.
 * @type {Error}
 */
DirectoryNotFoundException
/**
 * The file specified by path was not found.
 * @type {Error}
 */
FileNotFoundException
/**
 * An I/O error occurred while dealing with file.
 * @type {Error}
 */
IOException
/**
 * path exceeds the system-defined maximum length. For example, on Windows-based platforms,
 * paths must be less than 248 characters and file names must be less than 260 characters.
 * @type {Error}
 */
PathTooLongException
/**
 * path is in an invalid format.
 * @type {Error}
 */
NotSupportedException
/**
 * DirectoryWhileExpectedFileException, for example passing a directory to appendFile function
 * @type {Error}
 */
DirectoryWhileExpectedFileException
/**
 * FileWhileExpectedDirectoryException
 * @type {Error}
 */
FileWhileExpectedDirectoryException
/**
 * occured when path specifies a file that is read-only.
 * or have'nt access on file(no rigth)
 * or operation is not supported on the current platform.
 * @type {Error}
 */
UnauthorizedAccessException

Resume

/**
 *
 * @param {String|Buffer} path - path of file
 * @param {Number} mode
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 * @promise-error {FileNotFoundException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {SecurityException}
 * @promise-error {UnauthorizedAccessException}
 */
File.access
/**
 *
 * @param {Number|Buffer|String} file
 * @param data
 * @param options
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 * @promise-error {IOException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {UnauthorizedAccessException}
 */
File.appendFile
/**
 *
 * @param {String|Buffer} path
 * @param {Number} mode
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 * @promise-error {IOException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {UnauthorizedAccessException}
 * @promise-error {DirectoryNotFoundException}
 * @promise-error FileWhileExpectedDirectoryException
 */
File.chmod
/**
 *
 * @param {String|Buffer} path
 * @param {Number} uid
 * @param {Number} gid
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error ArgumentNullException
 * @returns {"bluebird"|any}
 */
File.chown
/**
 *
 * @param {Number} fd
 * @returns {"bluebird"|any}
 * @promise-error {IOException}
 */
File.close
/**
 *
 * @param path
 * @param {Object|undefined, null} options
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 */
File.createReadStream
/**
 *
 * @param path
 * @param {Object|undefined, null} options
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 */
File.createWriteStream
/**
 *
 * @param {String|Buffer} path
 * @returns {"bluebird"|any}
 * @promise-error ArgumentNullException
 * @promise-error ArgumentException
 * @promise-error IOException
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 */
File.exist
/**
 *
 * @param {String|Buffer} path
 * @param {Number} mode
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 * @promise-error {IOException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {UnauthorizedAccessException}
 * @promise-error {DirectoryNotFoundException}
 */
File.fchmod
/**
 *
 * @param {String|Buffer} path
 * @param {Number} uid
 * @param {Number} gid
 * @returns {"bluebird"|any}
 * @promise-error ArgumentNullException
 * @promise-error ArgumentException
 * @promise-error FileNotFoundException
 * @promise-error IOException
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error ArgumentNullException
 */
File.fchown
/**
 *
 * @param {Number} fd
 * @returns {"bluebird"|any}
 * @promise-error IOException
 * @promise-error ArgumentException
 */
File.fdatasync
/**
 *
 * @param {Number} fd
 * @returns {"bluebird"|any}
 * @promise-error IOException
 * @promise-error ArgumentException
 */
File.fstat
/**
 *
 * @param {Number} fd
 * @returns {"bluebird"|any}
 * @promise-error IOException
 * @promise-error ArgumentException
 */
File.fsync
/**
 *
 * @param {Number} fd
 * @param {Number} len
 * @returns {"bluebird"|any}
 * @promise-error ArgumentException
 * @promise-error IOException
 */
File.ftruncate
/**
 *
 * @param {Number} fd
 * @param {Number} atime
 * @param {Number} mtime
 * @returns {"bluebird"|any}
 * @promise-error IOException
 * @promise-error ArgumentException
 */
File.futimes
/**
 *
 * @param {Number} fd
 * @param {Number} mode
 * @returns {"bluebird"|any}
 * @promise-error IOException
 * @promise-error ArgumentException
 */
File.lchmod
/**
 *
 * @param {Number} fd
 * @param {Number} uid
 * @param {Number} gid
 * @returns {"bluebird"|any}
 * @promise-error IOException
 * @promise-error ArgumentException
 */
File.lchown
/**
 *
 * @param {String|Buffer} existingPath
 * @param {String|Buffer} newPath
 * @returns {"bluebird"|any}
 * @promise-error  {IOException}
 * @promise-error  {ArgumentException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {ArgumentNullException}
 */
File.link
/**
 *
 * @param {String|Buffer} path - path of file
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 * @promise-error {FileNotFoundException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {UnauthorizedAccessException}
 * @promise-error {IOException}
 */
File.lstat
/**
 *
 * @param {String|Buffer} path - path of file
 * @param {Number} mode
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 * @promise-error {FileNotFoundException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {UnauthorizedAccessException}
 * @promise-error {DirectoryNotFoundException}
 * @promise-error {IOException}
 */
File.mkdir
/**
 *
 * @param {String} prefix
 * @param {Object|String} options
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {IOException}
 */
File.mkdtemp
/**
 *
 * @param {String|Buffer} path
 * @param {String|Buffer} flags
 * @param {Number} mode
 * @returns {"bluebird"|any}
 * @promise-error DirectoryNotFoundException
 * @promise-error ArgumentException
 * @promise-error ArgumentNullException
 * @promise-error DirectoryNotFoundException
 * @promise-error FileNotFoundException
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 */
File.open
/**
 *
 * @param {Number} fd
 * @param {Buffer} buffer
 * @param {Number} offset
 * @param {Number} length
 * @param {Number|null?} position
 * @returns {"bluebird"|any}
 * @promise-error ArgumentException
 * @promise-error IOException
 */
File.read
/**
 *
 * @param {String|Buffer} path - path of file
 * @param {String|Object} options
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 * @promise-error {FileNotFoundException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {UnauthorizedAccessException}
 * @promise-error {DirectoryNotFoundException}
 * @promise-error {FileWhileExpectedDirectoryException}
 * @promise-error {IOException}
 */
File.readdir
/**
 *
 * @param {Number|Buffer|String} file
 * @param options
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 * @promise-error {IOException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {UnauthorizedAccessException}
 * @promise-error {DirectoryWhileExpectedFileException}
 */
File.readFile
/**
 *
 * @param {String|Buffer} path - path of file
 * @param {String|Object} options
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 * @promise-error {FileNotFoundException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {UnauthorizedAccessException}
 * @promise-error {DirectoryOrFileNotFoundException}
 * @promise-error {IOException}
 */
File.readlink
/**
 *
 * @param {String|Buffer} path
 * @returns {"bluebird"|any}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 */
File.realpath
/**
 *
 * @param {String|Buffer} existingPath
 * @param {String|Buffer} newPath
 * @returns {"bluebird"|any}
 * @promise-error  {IOException}
 * @promise-error  {ArgumentException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {ArgumentNullException}
 * @promise-error UnauthorizedAccessException
 * @promise-error FileNotFoundException
 */
File.rename
/**
 *
 * @param {String|Buffer} path
 * @returns {"bluebird"|any}
 * @promise-error ArgumentNullException
 * @promise-error ArgumentException
 * @promise-error IOException
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 */
File.stat
/**
 *
 * @param {Number|Buffer|String} file
 * @param data
 * @param options
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 * @promise-error {IOException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {UnauthorizedAccessException}
 */
File.writeFile
/**
 *
 * @param {Number} fd
 * @param {String} string
 * @param {Number|null?} position
 * @param {String} encoding
 * @returns {"bluebird"|any}
 * @promise-error ArgumentException
 * @promise-error IOException
 */
File.writeV0115
/**
 *
 * @param {Number} fd
 * @param {Buffer} buffer
 * @param {Number} offset
 * @param {Number} length
 * @param {Number|null?} position
 * @returns {"bluebird"|any}
 * @promise-error ArgumentException
 * @promise-error IOException
 */
File.writeV002
/**
 *
 * @param {Number} fd
 * @param {Buffer} buffer
 * @param {Number} offset
 * @param {Number} length
 * @param {Number|null?} position
 * @returns {"bluebird"|any}
 * @promise-error ArgumentException
 * @promise-error IOException
 */
File.write
/**
 *
 * @param {Number|Buffer|String} file
 * @param {Number?} len
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 * @promise-error {IOException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {UnauthorizedAccessException}
 * @promise-error {FileNotFoundException}
 */
File.truncate
/**
 *
 * @param {String|Buffer} path
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 * @promise-error {IOException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {UnauthorizedAccessException}
 * @promise-error {FileNotFoundException}
 */
File.unlink
/**
 *
 * @param path
 * @param listener
 * @returns {"bluebird"|any}
 * @promise-error {ArgumentNullException}
 * @promise-error {ArgumentException}
 * @promise-error {IOException}
 * @promise-error {PathTooLongException}
 * @promise-error {NotSupportedException}
 * @promise-error {UnauthorizedAccessException}
 * @promise-error {FileNotFoundException}
 */
File.unwatchFile