3.0.3 • Published 10 years ago

directory-cache v3.0.3

Weekly downloads
31
License
-
Repository
-
Last release
10 years ago

Directory Cache

A directory cache, built on top of DirectoryWatcher. The cache reads all the files in a directory and caches their content. When files are changed, added, deleted etc the cache will update and fire an event using the good old EventEmitter API.

Install

	npm install directory-cache

Example

var DirectoryCache = require('directory-cache');

var cache = DirectoryCache.create({
	directory: '/path/to/the/moon'
}/*, optionally supply a callback to automatically call .init */);

cache.on('add', function(files) {
	var content = cache.getFileContent(files[0]);
	// do something with content
});

cache.on('change', function(files) {
	// etc...
});

cache.on('delete', function(files) {
	// etc..
});

cache.on('error', function(err) {
	// waaaaaaaaah!
})

cache.init(function(err) {
	if (err) 
		return console.log('ahhhhhhhhhhhh!', err);

	var content = cache.getFileContent('moo.txt'); // returns the content of /path/to/the/moon/moo.txt

	var files = cache.getFiles(); // returns all the files in /path/to/the/moon

});

using filters

// regular expression retains only json files

var DirectoryCache = require('directory-cache');

var cache = DirectoryCache.create({
	directory: '/path/to/the/moon',
	filter: /.*json/
});

// function filter that retains only json files

var cache2 = DirectoryCache.create({
	directory: '/path/to/the/moon',
	filter: function(file) { return file.slice(-5).toLowerCase() === '.json' }
});
3.0.3

10 years ago

3.0.2

10 years ago

3.0.1

10 years ago

3.0.0

10 years ago

2.0.3

10 years ago

2.0.2

10 years ago

2.0.1

10 years ago

1.0.4

11 years ago

1.0.3

11 years ago

1.0.2

11 years ago

1.0.0

11 years ago