Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

directory-cache

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

directory-cache

A directory cache + watch util

  • 3.0.3
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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' }
});

FAQs

Package last updated on 28 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc