npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

jvfs

2.0.1 • Public • Published

JSON Virtual FileSystem

I have searched over and over for a virtual filesystem module but found none that are just easy to use, so here we go.

Usage:

var jvfs_mod=require("jvfs");
var jvfs=jvfs_mod();
// jvfs import/export
jvfs.importfile(path2jvfs); // import jvfs instance from a file
jvfs.exportfile(path2jvfs); // export a jvfs instance to a file
jvfs.exportfs();            // obtain base64 encoded json encoded result of the jvfs
jvfs.importfs(b64code);     // import base64 encoded json encoded data of a jvfs filesystem

New permissions system:

var jvfs_mod=require("jvfs");
var jvfs=jvfs_mod(true);                // optional bool oftrue, toenable the permissions system
// permissions users
jvfs.perms.adduser({user:"user"});      // add a user to the permissions system
jvfs.perms.deluser("user");             // delete a user from the permissions system
// read permissions
jvfs.perms.read.aod(user,bool);         // true = prefer to check allowed over denied access for reading
jvfs.perms.read.add.allow(user,path);   // add an allowed path fora user
jvfs.perms.read.add.deny(user,path);    // add a denied pathfora user
jvfs.perms.read.del.allow(user,path);   // delete an allowed path for a user
jvfs.perms.read.del.deny(user,path);    // delete a denied path for a user
// write permissions
jvfs.perms.write.aod(user,bool);        // true = prefer to check allowed over denied access for writing
jvfs.perms.write.add.allow(user,path);  // add an allowed path fora user
jvfs.perms.write.add.deny(user,path);   // add a denied pathfora user
jvfs.perms.write.del.allow(user,path);  // delete an allowed path for a user
jvfs.perms.write.del.deny(user,path);   // delete a denied path for a user
// jvfs import/export
jvfs.importfile(path2jvfs);             // import jvfs instance from a file
jvfs.exportfile(path2jvfs);             // export a jvfs instance to a file
jvfs.exportfs();                        // obtain base64 encoded json encoded result of the jvfs
jvfs.importfs(b64code);                 // import base64 encoded json encoded data of a jvfs filesystem
// File commands
jvfs.writefile(path,value,user);        // true - false , user needed if permissions enabled
jvfs.readfile(path,user);               // contents - false , user needed if permissions enabled
jvfs.deletefile(path,user);             // true - false , user needed if permissions enabled
// Folder commands
jvfs.mkdir(path,user);                  // true - false , user needed if permissions enabled
jvfs.readdir(path,user);                // list of files in path - false , user needed if permissions enabled
jvfs.rmdir(path,user);                  // true - false , user needed if permissions enabled
// File + Folder commands
jvfs.type(path,user);                   // file - folder - false , user needed if permissions enabled
jvfs.exists(path,user);                 // true - false , user needed if permissions enabled
jvfs.resolve(path);                     // cleaned relative path
jvfs.parent(path);                      // returns relative path to supposed parent folder of path

path is relative to its virtual "root", so if no / is prepended, it will auto prepend to accomodate for relative paths

Exmple:

var jvfs=require("jvfs");               // load module
var fs=jvfs(true);                      // create a vfs with permissions enabled
fs.perms.adduser({user:"root"});        // add a new user to permissions system
fs.perms.write.aod(true);               // enable allow over deny checking
fs.perms.write.add.allow("root","/");   // allow to access path /
fs.mkdir("/folder1","root");            // returns true

install

npm i jvfs

Downloadsweekly downloads

0

version

2.0.1

license

ISC

last publish

collaborators

  • avatar
Report a vulnerability