webpack / memory-fs

[DEPRECATED use memfs instead] A simple in-memory filesystem. Holds data in a javascript object.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add mounting of other memory-fs filesystems

jsProj opened this issue · comments

`function MemoryFileSystem(data) {
	this.data = data || {};
    this.data[""]=true;
    this.data["/"]={
        isMount:false,
        mounts:{}
    };
}
MemoryFileSystem.prototype.mount = function(fs,path){
    try{
        this.writeFileSync(path,fs.data);
    }catch(e){
        throw new Error("Cannot mount "+path+" error: "+e.message);
    }
    fs.data["/"].isMount=true;
    this.data["/"].mounts[path]=fs;
}
MemoryFileSystem.prototype.unmount = function(path){
    if(this.data["/"].mounts[path]!==undefined){
        var ff=this.data["/"].mounts[path];
        ff.data["/"].isMount=false;
        this.rmdirSync(path);
        delete this.data["/"].mounts[path];
    }else{
        throw new Error("Path not a mount point!");
    }
}`

resulting in succes:

===================createing both folders
{ '': true,
  '/': { isMount: false, mounts: {} },
  a: { '': true } }
{ '': true,
  '/': { isMount: false, mounts: {} },
  b: { '': true } }
===================creating a file on f2
{ '': true,
  '/': { isMount: false, mounts: {} },
  a: { '': true } }
{ '': true,
  '/': { isMount: false, mounts: {} },
  b:
   { '': true,
     'one.txt': <Buffer 68 65 6c 6c 6f 20 70 65 6f 70 6c 65> } }
===================mounting f2 to f1
{ '': true,
  '/': { isMount: false, mounts: { '/m1': [Object] } },
  a: { '': true },
  m1:
   { '': true,
     '/': { isMount: true, mounts: {} },
     b:
      { '': true,
        'one.txt': <Buffer 68 65 6c 6c 6f 20 70 65 6f 70 6c 65> } } }
{ '': true,
  '/': { isMount: true, mounts: {} },
  b:
   { '': true,
     'one.txt': <Buffer 68 65 6c 6c 6f 20 70 65 6f 70 6c 65> } }
===================deleting file on f2 from f1
{ '': true,
  '/': { isMount: false, mounts: { '/m1': [Object] } },
  a: { '': true },
  m1: { '': true, '/': { isMount: true, mounts: {} }, b: { '': true } } }
{ '': true, '/': { isMount: true, mounts: {} }, b: { '': true } }
===================unmounting f2 from f1
{ '': true,
  '/': { isMount: false, mounts: {} },
  a: { '': true } }
{ '': true,
  '/': { isMount: false, mounts: {} },
  b: { '': true } }

just replace with the coe iprovided, (edited from npm source)