Skip to content
This repository has been archived by the owner on Nov 21, 2020. It is now read-only.

Eomm/file-utils-easy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

file-utils-easy

Coverage Status

This is a simply file utils lib.

Installation

npm install file-utils-easy

WARNING: this package has been deprecated, upgrade your Node.js version and use default fs module instead.

Usage

const fue = require('file-utils-easy');

fue.readDirectoryFiles('path/')
  .then(files => doSomething(files))
  .catch(err => doSomethingElse())

API

file-utils-easy~writeToFile(fileContent, filePath) ⇒ Promise.<string>

Write a string to a file

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the filePath received in input

Param Type Description
fileContent string the payload of the file
filePath string path and filename: where store the file

file-utils-easy~writeToFileStream(fileStream, filePath) ⇒ Promise

Write a stream to a file

Kind: inner method of file-utils-easy
Returns: Promise - resolve with the filePath when the stream finish

Param Type Description
fileStream stream the stream payload
filePath string path and filename: where store the file

file-utils-easy~appendToFile(fileContent, filePath) ⇒ Promise.<string>

Append a string to a file

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the filePath received in input

Param Type Description
fileContent string the payload of the file
filePath string path and filename: where store the file

file-utils-easy~readFileStats(filePath) ⇒ Promise.<fs.Stats>

Read the metadata of the file

Kind: inner method of file-utils-easy
Returns: Promise.<fs.Stats> - a node fs.Stats that provides information about a file
See: https://nodejs.org/api/fs.html#fs_class_fs_stats

Param Type Description
filePath string path and filename: the file to read

file-utils-easy~readDirectoryFiles(directory) ⇒ Promise.<array>

List the files names of a directory, ignoring directories

Kind: inner method of file-utils-easy
Returns: Promise.<array> - strings names of the files in the input directory

Param Type Description
directory string path of the directory to read

file-utils-easy~readFile(filePath, [encoding]) ⇒ Promise.<string>

Read the content of a file

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the string content of the file

Param Type Default Description
filePath string path and filename: the file to read
[encoding] string "'utf8'" the encoding file

file-utils-easy~readJsonFile(filePath) ⇒ Promise.<object>

Read the content of a file as a UTF8 string and then parse it as a JSON

Kind: inner method of file-utils-easy
Returns: Promise.<object> - resolve with the JSON content of the file

Param Type Description
filePath string path and filename: the file to read

file-utils-easy~saveUrlToFile(url, filePath) ⇒ Promise.<string>

Save the content of a url to a file

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the filePath saved

Param Type Description
url string where will be done an HTTP/GET to get the content
filePath string path and filename where store the output of url

file-utils-easy~deleteFile(filePath) ⇒ Promise.<string>

Delete a file from the file system

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the filePath deleted

Param Type Description
filePath string path and filename: the file to delete

file-utils-easy~deleteDirectoryFiles(directory) ⇒ Promise.<array>

Delete all the files in a directory, applying an optional filter

Kind: inner method of file-utils-easy
Returns: Promise.<array> - resolve with all the files deleted succesfully

Param Type Description
directory string path of the directory to clean

file-utils-easy~renameFile(from, to) ⇒ Promise.<string>

Rename a file to another path

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the destination filePath

Param Type Description
from string origin path and filename
to string destination path and filename

file-utils-easy~copyFile(from, to) ⇒ Promise.<string>

Copy a file to another path

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the destination filePath

Param Type Description
from string origin path and filename
to string destination path and filename

file-utils-easy~existFile(filePath) ⇒ Promise.<string>

Check if a file exists

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the filePath that exists
Throws:

  • error if the file doesn't exist
Param Type Description
filePath string path and filename: the file to control

Test

For run the tests simply execute:

npm test

License

Copyright Manuel Spigolon, Licensed under MIT.