A recursive file emitter
Stability: 3 - Stable
Create a new FileEmitter
object, extends events.EventEmitter
.
{string} folder
{?Object} opt_options
opt_options
{boolean} buffer
Load each file into a buffer before emitting, defaults tofalse
{number} maxBufferSize
The max size of a file buffer, defaults to10485760
(=10MiB){boolean} incremental
Whentrue
eachfile
event has to be acknowledged by callingfe.next()
{boolean} followSymLinks
..., defaults tofalse
{boolean} recursive
..., defaults totrue
{boolean} autorun
..., defaults totrue
{Array<string>} exclude
glob patterns applied afterreadir
{Array<string>} include
glob patterns applied afterstat
{Object} minimatchOptions
Seeminimatch
README, defaults to{matchBase: true}
{Function} File
A custom constructor for file objects, has to extendFile
var fileEmitter = require('file-emitter');
var fe = fileEmitter('./lib', {
buffer: true,
incremental: true,
include: ['*.js'],
exclude: ['.git', 'node_modules', 'coverage', 'test']
});
fe.on('file', function(file) {
// {string} file.name
// {fs.Stats} file.stats
// {?Buffer} file.buffer
if (!file.buffer) { // maxBufferSize exceeded
var readableStream = file.createReadStream();
}
// acknowledge that the file has been processed
// see 'incremental' option
fe.next();
});
fe.on('error', function(err) { }); // everything but EMFILE
fe.once('end', function(hadError) { });
Manually start scanning the folder & emitting files when autostart=false
.
When the emitter runs with incremental = true
a call to next()
is required after each file
event to acknowledge that the file has been processed.
Used to process files asynchronously while preventing allocation of large queues & file buffers.
Convenience method to retrieve a list of files.
opt_options
- all options of
fileEmitter()
except forincremental
&autorun
{function(File, File)} compare
A compare function passed toArray.sort()
fileEmitter.list('./', {
compare: function(a, b) {
return a.stats.size - b.stats.size;
}
}, function(err, files) { });
npm test
firefox coverage/lcov-report/index.html
Statements : 94.05% ( 174/185 )
Branches : 89.90% ( 89/99 )
Functions : 100% ( 21/21 )