file-utils-easy
This is a simply file utils lib.
Installation
npm install file-utils-easy
Usage
const fue = ; fue
API
- file-utils-easy
- ~writeToFile(fileContent, filePath) ⇒
Promise.<string>
- ~writeToFileStream(fileStream, filePath) ⇒
Promise
- ~appendToFile(fileContent, filePath) ⇒
Promise.<string>
- ~readFileStats(filePath) ⇒
Promise.<fs.Stats>
- ~readDirectoryFiles(directory) ⇒
Promise.<array>
- ~readFile(filePath, [encoding]) ⇒
Promise.<string>
- ~readJsonFile(filePath) ⇒
Promise.<object>
- ~saveUrlToFile(url, filePath) ⇒
Promise.<string>
- ~deleteFile(filePath) ⇒
Promise.<string>
- ~deleteDirectoryFiles(directory) ⇒
Promise.<array>
- ~renameFile(from, to) ⇒
Promise.<string>
- ~copyFile(from, to) ⇒
Promise.<string>
- ~existFile(filePath) ⇒
Promise.<string>
- ~writeToFile(fileContent, filePath) ⇒
Promise.<string>
file-utils-easy~writeToFile(fileContent, filePath) ⇒ 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 |
Promise
file-utils-easy~writeToFileStream(fileStream, filePath) ⇒ 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 |
Promise.<string>
file-utils-easy~appendToFile(fileContent, filePath) ⇒ 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 |
Promise.<fs.Stats>
file-utils-easy~readFileStats(filePath) ⇒ 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 |
Promise.<array>
file-utils-easy~readDirectoryFiles(directory) ⇒ 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 |
Promise.<string>
file-utils-easy~readFile(filePath, [encoding]) ⇒ 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 |
Promise.<object>
file-utils-easy~readJsonFile(filePath) ⇒ 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 |
Promise.<string>
file-utils-easy~saveUrlToFile(url, filePath) ⇒ 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 |
Promise.<string>
file-utils-easy~deleteFile(filePath) ⇒ 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 |
Promise.<array>
file-utils-easy~deleteDirectoryFiles(directory) ⇒ 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 |
Promise.<string>
file-utils-easy~renameFile(from, to) ⇒ 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 |
Promise.<string>
file-utils-easy~copyFile(from, to) ⇒ 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 |
Promise.<string>
file-utils-easy~existFile(filePath) ⇒ 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.