1.0.0 • Published 10 years ago

virtual-folder v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

virtual-folder

NPM version Build Status Dependency Status

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), or null (meaning 'delete').
  • If the call results in a change, the folder will emit a 'change' event with a Change object (see below). The .write() call will also return the Change object.
  • If the call results in no change, it returns null.
.read(file)
  • Returns the contents for file, or null if the file doesn't exist.

Change objects

Properties:

  • file – string
  • type - string (either "add", "modify" or "delete")
  • contents – buffer (or null if this change is a "delete")
  • oldContents – buffer (or null 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

1.0.0

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.2

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago