1.2.5 • Published 8 years ago

dir-in-ram v1.2.5

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

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)

1.2.5

8 years ago

1.2.4

8 years ago

1.2.3

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.5

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago