1.0.0 • Published 10 years ago
virtual-folder v1.0.0
virtual-folder
A class for an in-memory 'folder' – a place to store buffers with associated file paths. Does not care whether the files actually exist anywhere on disk.
You could just use a plain JavaScript object for the same purpose, but this class adds events and some sugar.
Install
$ npm install virtual-folderUsage
var folder = new Folder();
folder.write('some/file.txt', 'hello'); // returns Change object (see below)
folder.read('some/file.txt'); // returns Buffer('hello');Methods
.write(file, contents)
contentscan be a buffer, a string (which will be converted to a buffer), ornull(meaning 'delete').- If the call results in a change, the folder will emit a
'change'event with aChangeobject (see below). The.write()call will also return theChangeobject. - If the call results in no change, it returns
null.
.read(file)
- Returns the contents for
file, ornullif the file doesn't exist.
Change objects
Properties:
file– stringtype- string (either"add","modify"or"delete")contents– buffer (ornullif this change is a "delete")oldContents– buffer (ornullif this change is an "add")
It also has an .inspect() method, so when you console.log a change object, it looks something like this:
<CHANGE modify some/foo.txt (12KB => 13KB)>License
MIT