1.0.5 • Published 4 years ago

node-file-ops v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

node-file-ops

The module works as a wrapper for the fs/filesystem module that is contained in node systems. With that as the only dependency it is very light-weight and can make your file handling procedures very easy. All api calls provided by the module for files include:

read-file : files support for txt,json, and md.
read-dir : shows an array of files contained in a filesystem directory.
Create : create files.
Copy : make duplicates.
cut : will copy and then delete previous source file.
Rename : rename your files.
Delete : permanently removes file from directory.
Upcoming features
dirSync : synchronize two directories, a master and secondary directory

.

USAGE :

Step 1

Add the module into your applications dependencies by command:

npm i -S node-file-ops
step 2

Then to use the module's functions in your script require it:

const fileOps = require('node-file-ops')
step 3

The next step is to utilize the module we have imported in our script by making a call to the fileOps function and passing in a json object containing arguements of operations to be perfomed to files on a directory.

Acceptable arguments

Create a variable content that will be a container for the files data be manipulated:

var content;

The complete json parameters will look like this:

var file = {
    src:'',
    dest:'',
    fileType:'',
    operation:'',
    content: content
};

The content container will always be passed as an arguement to the object in all the operations.

read files

Requires three arguments:

var content;
var file = {
    src:'directory/to/destinationFile/myFile.extension',
    dest:'',
    fileType:'',
    operation:'read-file',
    content: content
};

The source "src:" and "operation:" arguements are mandatory. Read file support for file-types txt,json, and md at the moment. Support for pdf,doc/docx and other documents to be included in upcoming releases.

reading directory contents

Requires four arguements:

var content;
var file = {
    src:'directory/path/',
    dest:'',
    fileType:'',
    operation:'read-dir',
    content: content
};

Pass in arguments for the source "src:" and the operation type.

creating files

Requires three arguments:

var content;
var file = {
    src:'',
    dest:'directory/to/destinationFile/',
    fileType:'fileType.extension',
    operation:'create',
    content: content
};

Pass in the destination "dest:" and "fileType:" arguements. Remember to also include the extension type of the file to be created when specifying the "fileType:" arguement. When creating files also include the content of data to be saved in the file. This can be such as; a string, buffer object, or other basic data types used for files depending also on the "fileType:" specifications. If file already exists, the content will be appended to the existing data.

making a file copy, cut, or rename.

Requires four arguements:

var content;
var file = {
    src:'directory/to/sourceFile.extension',
    dest:'directory/to/destinationFile.extension',
    fileType:'',
    operation:'copy, cut, or rename',
    content: content
};

Pass in arguments for the source "src:", destination "dest:" of a file as well as for the operation type such as; "copy, cut, or rename" in the objects parameters as shown. Makes sure when specifying the source and destination to add the file extension type as well.

delete file

Requires four arguements:

var content;
var file = {
    src:'directory/to/sourceFile.extension',
    dest:'',
    fileType:'',
    operation:'delete',
    content: content
};

The example shows the arguements expected for a file delete operation.

Code Examples

Example 1.
const fileOps = require('node-file-ops')
var content;
var file = {
    src:'directory/to/sourceFile.extension',
    dest:'directory/to/destinationFile.extension',
    fileType:'',
    operation:'copy, cut, or rename',
    content: content
};

fileOps(file);
Example 2.
const fileOps = require('node-file-ops')
var content="Hello World!";
var file = {
    src:'',
    dest:'directory/to/destinationFile/',
    fileType:'myFile.txt',
    operation:'create',
    content: content
};

fileOps(file);
Example 3.
const fileOps = require('node-file-ops')
var content;
var file = {
    src:'directory/path/',
    dest:'',
    fileType:'',
    operation:'read-dir',
    content: content
};

fileOps(file);

Developer: Antony Otieno

Email: antony.otieno.onyango@gmail.com

Github: www.github.com/code-ddicted

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago