FSGOD (Alpha)
A service for securely managing, transfering, collaborating, and hosting content on your local network
The only component thus far is the Virtual Directory Tree (VDT).
The purpose of this library is to make dynamic managing of any size of file system easy and quick.
API
VDT
Recursively step through a file tree to create a 'Virtual File Tree' which allows for quicker data processing and greater control over your file system
const fsgod = require('fsgod');
fsgod.VDT('./', (vdt) => {
var myDirectory = vdt;
for ( var i = 0; i < myDirectory.content.length; i++ ){
console.log(myDirectory.content[i].name);
}
});
The above code should log the names of all the items in the directory it's currently in
The vdt
object that gets passed to the callback in fsgod.VDT
is the Virtual Directory Tree. fsgod.VDT
recursively walks through a specified folder and builds each item into a JavaScript object and passes it back to the user in the callback. For the meantime, fsgod.VDT
can only be used to read and search file system data and content. If you'd like to help, email me at maui.wowie@tuta.io.
VDT.search
Every directory in the VDT (including the root/target directory) has a search method. The search method uses regular expressions to locate any item containing the string passed in the first argument.
fsgod.VDT('./', (vdt) => {
var myDirectory = vdt;
myDirectory.search('test', { content: false }, (results) => {
console.log('Found ' + results.length + ' items');
for (var i = 0; i < results.length; i++){
console.log(results[i].fullPath);
}
});
});
The above code should find file names and directory names that contain the phrase 'test' and print their full paths.
You should notice the second argument takes an object which specifies search options; in the case of the above example, we don't want to look through file content for our search string, just names. This argument is optional and simply calling:
vdt.search('test', (results) => {
console.log('Found ' + results.length + ' items');
for (var i = 0; i < results.length; i++){
console.log(results[i].fullPath);
}
});
Will return the search results without any filters.
The filter options you can give to the object are
Filter | Type | Usage |
---|
content | Boolean | Decides whether or not to search file content for results |
names | Boolean | Decides whether or not to search file/directory names for results |
files | Boolean | Decides whether or not to include files in search results |
directories | Boolean | Decides whether or not to include directories in results |
excludes | Array | Any search results containing a string in the 'excludes' array will be removed |
Virtual Directory
Each directory in the vdt callback is it's own Virtual Directory Tree with the same methods as the intial target directory
Key | Type | Usage |
---|
content | Array | An array of both directories (VDT's) and files |
name | String | The name of the file or directory |
type | String | Will let you know if its a directory or file |
fullPath | String | The full path to the item |
size | Integer | Size of the item in bytes |
search | Function | Search in and under the directory for a search string |
Virtual File
Key | Type | Usage |
---|
content | String | File contents |
name | String | File name |
type | String | Will let you know if it's a directory or file |
fullPath | String | The full path to the item |
size | Integer | Size of the item in bytes |