fs-operations v1.0.15
FS-Operation v1.0.0
The fsOperations library exported as Node.js modules.
Docs
Various File Operations: Encrypt, Decrypt, FileExists, FolderExists, getFileSpecs, listDirectory.
Installation
npm install fs-operations
Key
Create a KEY object to be used by Encryption/Decryption functions that contains the password and encryption type
This object can be any data you wish to tie the license to - format Object
options: {password:"samplePass123", algorithm:"aes-256-ctr"} - (default algorithm is "aes-256-ctr")
Must include: password (string)
var key = new fsOperations.Key({password:'samplePass123'});
Init
var fsOperations = require('fs-operations');
Decrypt/Encrypt
Create a KEY (object) that contains the password and encryption type (algorithm) Object structure foe the key is: {password:'123456', algorithm:'aes-256-ctr'} If you exclude the algorithm, the default 'aes-256-ctr' is used
var fsOperations = require('fs-operations');
var key = {password2:'samplePass123'};
//encrypt
try{
var specsE = fsOperations.encrypt(theStr,key);
console.log(specsE);
}catch(err){
console.log(err);
}
//decrypt
try{
var specsD = fsOperations.decrypt(specsE,key);
console.log(specsD);
}catch(err){
console.log(err);
}
Folder Exists
Checks is a Directory Exists. Provide a path and true/false to create new empty directory if none exists:
var fsOperations = require('fs-operations');
var aPath = '/Users/mikeboni/Desktop/sampleProject/routes/sample';
try{
fsOperations.folderExists(aPath, true, function(result){
console.log(result);
});
}catch(err){
console.log(err);
}
The function will return boolean: true/false
File Exists
Checks is a File Exists. Provide a path and true/false and if you want to create a new empty file if none exists:
var fsOperations = require('fs-operations');
var aPath = '/Users/mikeboni/Desktop/sampleProject/routes/sample/sample.html';
try{
fsOperations.fileExists(aPath, true, function(result){
console.log(result);
});
}catch(err){
console.log(err);
}
The function will return boolean: true/false
getFileSpecs
Retrieves file information: type:(file/directory), size:(integer), modified:(date), created:(date), file:(sample), ext:(.html), filename:(sample.html)
var fsOperations = require('fs-operations');
var aPath = '/Users/Guest/Desktop/sampleProject/samplefolder/index.js';
try{
fsOperations.getFileSpecs(aPath, function(result){
console.log(result);
});
}catch(err){
console.log(err);
}
returns object:
{ type: 'file', size: 205, modified: 2016-12-06T19:10:49.000Z, created: 2016-12-06T19:10:49.000Z, file: 'index', ext: 'js', filename: 'index.js' }
listDirectory
Get contents of a directory. You can specify the types (file/folder) and filter by file extension. NOTE: Recursive NOT implemented
options: {type:'file', ext:'md'}
type: file or directory ext: extention like .js, .md, wrd, .txt (you can include '.' for ext if you wish) default is 'all'
var fsOperations = require('fs-operations');
var aPath = '/Users/user/Desktop/sampleProject/aFolder';
var options = {type:'file', ext:'md'};
try{
fsOperations.listDirectory(aPath, options, function (result){
console.log(result.length);
console.log(result);
})
}catch(err){
console.log(err);
}
The function will return array of objects:
[
{ file: 'Readme',
size: 3375,
modified: 2016-12-14T17:35:19.000Z,
created: 2016-12-14T17:35:19.000Z,
ext: 'md',
filename: 'Readme.md',
isFile: true },
{ file: 'Readme2',
size: 3375,
modified: 2016-12-14T17:35:19.000Z,
created: 2016-12-14T17:35:19.000Z,
ext: 'md',
filename: 'Readme2.md',
isFile: true }
]
Support
Tested in Chrome 53-54, Firefox 48-49, IE 11, Edge 14, Safari 9-10, Node.js 6-7, & PhantomJS 2.1.1. Automated test runs are available.