dir-in-ram

1.2.5 • Public • Published

dir-in-ram

Load a directory tree into RAM, represented as an object/associative array of filename to data (the '.' field is special, representing the data of dir-in-ram for that directory, everything else is yours).

There are all kinds of uses for this. It could be a simple cache, or it could allow continuous integration or specialised file parsing alongside caching.

Quick start

The callback is called once it has loaded everything. You can work without a callback so long as you are happy that it may be incorrect for the first second or so.

This loads everything in the relative directory sql. ` var dir-in-ram = require('dir-in-ram') , sql = new dir-in-ram('./sql', console.log) ;

false { '.': [Object] , 'selectUsers.sql': '-- comment\nSELECT * FROM users;' , 'rebuild.sh' } `

This only loads files that end in sql: ` sql = new dir-in-ram({ directory: './sql' , acceptor : function(filename) { return !filename.startsWith('.') // No hidden files && !filename.endsWith('~') // No temporary files && filename.endsWith('.sql') ; } }, console.log);

false { '.': [Object] , 'selectUsers.sql': '-- comment\nSELECT * FROM users;' } `

This is a basic parser example: ` sql = new dir-in-ram({ directory: './sql' , parser : function(filename, data, done) { data = data.split('\n').filter(function(line) { return !line.startsWith('--'); }).join('\n'); done(false, data); } , acceptor : function(filename) { return !filename.startsWith('.') // No hidden files && !filename.endsWith('~') // No temporary files && filename.endsWith('.sql') ; } }, console.log);

false { '.': [Object] , 'selectUsers.sql': '-- comment\nSELECT * FROM users;' } `

There are also the parameters

encoding (default 'utf8'. Use null for byte array)

change_listener (function(event, filename). default empty function)

Readme

Keywords

none

Package Sidebar

Install

npm i dir-in-ram

Weekly Downloads

1

Version

1.2.5

License

MIT

Last publish

Collaborators

  • gaussflayer