javascript - Simulate File System in JSON -


i'm trying imitate file system in json. purpose detect whether "file" exists or not. thinking of structure this:

var fs = {   somename: {     type: 'directory',     contents: {       somenamechild: {         type: 'directory',         contents: {           somechild: {             type: 'file',             contents: 'hello world!'           }         }       }     }  } } 

after seeing started wondering if knows of simulate file system in-memory in json. don't want have write of createdirectory, createfile, removedirectory, removefile, etc. file operatons. don't need robust in terms of file storage. i'm more interested in directory structure operations.

does know of code can this? figure has tackled this.

thanks!

a dictionary has need, explicit type fields should not needed, @ least not if scope folders , files.

{    foldera : {        foldernested : {            somefile : "foo content"        },         foldernestedb : {         },    } } 

you have implement directory operations, pretty straightforward. example, navigate path in file system simply

var pieces = path.split('/');  var node = root;  (var = 0; < pieces.length; ++i) {     node = node[pieces[i]];     if (!node) {        // error, not found     }     break; }  // |node| file/folder 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -