virtual-folder
v1.0.0
Published
In-memory holding place for temp files in a build pipeline.
Downloads
15
Readme
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-folder
Usage
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)
contents
can 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 aChange
object (see below). The.write()
call will also return theChange
object. - If the call results in no change, it returns
null
.
.read(file)
- Returns the contents for
file
, ornull
if the file doesn't exist.
Change objects
Properties:
file
– stringtype
- string (either"add"
,"modify"
or"delete"
)contents
– buffer (ornull
if this change is a "delete")oldContents
– buffer (ornull
if 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