docs: function VirtualFileSystem ( file ) {
   var defaultFile = file || "./virtual.vfs";
   return ({
      "export":function(){
          //note - devices are not properly exported because functions cannot be serialised.
          return JSON.stringify({
              "root": Module.FS.root,
              "nextInode": Module.FS.nextInode
          });
      },
      "import": function( data ){
          var importedFS = JSON.parse(data);
          //link devices to alreardy initialised file system. 
          //we should import a vfs early on and preferably once on initial launch of the application - (circular refrences below
          //could keep the FS data from being garbage collected?
          importedFS.root.contents['dev'].contents['random'].input = Module.FS.root.contents['dev'].contents['random'].input;
          importedFS.root.contents['dev'].contents['random'].output = Module.FS.root.contents['dev'].contents['random'].output;
          importedFS.root.contents['dev'].contents['urandom'].input = Module.FS.root.contents['dev'].contents['urandom'].input;
          importedFS.root.contents['dev'].contents['urandom'].output = Module.FS.root.contents['dev'].contents['urandom'].output;
          importedFS.root.contents['dev'].contents['stdout'].output = Module.FS.root.contents['dev'].contents['stdout'].output;
          importedFS.root.contents['dev'].contents['stdin'].intput =  Module.FS.root.contents['dev'].contents['stdin'].input;
          importedFS.root.contents['dev'].contents['stderr'].output = Module.FS.root.contents['dev'].contents['stderr'].output;
          importedFS.root.contents['dev'].contents['tty'].output = Module.FS.root.contents['dev'].contents['tty'].output;
          importedFS.root.contents['dev'].contents['tty'].input = Module.FS.root.contents['dev'].contents['tty'].input;
  
          //var open_streams = Module.FS.streams.length;
          //if(open_streams > 3) console.log("= VFS Import Warning:",open_streams - 3," files open.");//how to handle this case?
          
          //link default streams to imported devices -- this might not really be necessary..
          //stdin stream
            Module.FS.streams[1].object = importedFS.root.contents['dev'].contents['stdin'];
          //stdou stream
            Module.FS.streams[2].object = importedFS.root.contents['dev'].contents['stdout'];
          //stderr stream
            Module.FS.streams[3].object = importedFS.root.contents['dev'].contents['stderr'];
  
          Module.FS.root = importedFS.root;
          Module.FS.nextInode = importedFS.nextInode;
  
      },
      "load": function( filename ){
          if(!fs) return;
          var realFile = filename || defaultFile;
          try{
              console.error("loading virtual file system:",realFile);
              var data = fs.readFileSync(realFile);
              this.import(data);
          }catch(e){
              console.error( e );
          }
          return this;
      },
      "save": function (filename){
          if(!fs) return;
          var realFile = filename || defaultFile;
          console.error("saving virtual filesystem to:",realFile);
          fs.writeFileSync(realFile,this.export());
          return this;
      },
      "importFile": function (source,destination,decrypt){
          //cp a file from real file system to virtual file system - full paths must be specified.
          if(!fs) return;
          destination = destination || source.substr(0);
          destination = path_vfs(destination);
          source = path_real(source);
          var target_folder, data, virtual_file;
          var filename = destination.split('/').reverse()[0];
          if( filename ){
              target_folder = Module.FS_findObject(path_vfs(path.dirname(destination)));
              if(!target_folder){
                  target_folder = Module.FS_createPath("/",path_vfs(path.dirname(destination)),true,true);
              }
              if(target_folder){
                if( fs_existsSync(source) ){
                  data = fs.readFileSync(source);
                  data = decrypt ? decrypt(data) : data;
                  virtual_file = Module.FS_createDataFile(target_folder,filename,data,true,true);
                }else console.error("importing to vfs, file not found.",source);
              }
          }
      },
      "exportFile": function (source,destination,encrypt){
          //cp a file from virtual file system to real file system
          if(!fs) return;
          var data,fd;
          destination = destination || source.substr(0);//export to same path
          destination = path_real(destination);
          source = path_vfs(source);
          //TODO preserve same file permissions (mode) - make sure files only readable by user
          var data = Module.FS_readDataFile(source);
          if(data){
              data = encrypt ? encrypt(data) : data;
              if(!fs_existsSync(path_real(path.dirname(destination)))) fs.mkdirSync(path_real(path.dirname(destination)));
              fd = fs.openSync(destination,"w");
              fs.writeSync(fd,data,0,data.length,0);
              fs.closeSync(fd);        
          }else console.error("virtual file not found",source);
      }
   });
  }