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

file-emitter

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-emitter

A recursive file emitter

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

file-emitter

NPM version downloads node version Build Status

A recursive file emitter

Stability: 3 - Stable

fileEmitter(folder, opt_options)

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 to false
  • {number} maxBufferSize The max size of a file buffer, defaults to 10485760 (=10MiB)
  • {boolean} incremental When true each file event has to be acknowledged by calling fe.next()
  • {boolean} followSymLinks ..., defaults to false
  • {boolean} recursive ..., defaults to true
  • {boolean} autorun ..., defaults to true
  • {Array<string>} exclude glob patterns applied after readir
  • {Array<string>} include glob patterns applied after stat
  • {Object} minimatchOptions See minimatch README, defaults to {matchBase: true}
  • {Function} File A custom constructor for file objects, has to extend File
Example
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) { });

fe.run()

Manually start scanning the folder & emitting files when autostart=false.

fe.next()

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.

fileEmitter.list(folder, opt_options, callback)

Convenience method to retrieve a list of files.

opt_options

  • all options of fileEmitter() except for incremental & autorun
  • {function(File, File)} compare A compare function passed to Array.sort()
Example
fileEmitter.list('./', {
  compare: function(a, b) {
    return a.stats.size - b.stats.size;
  }
}, function(err, files) { });

Tests

npm test
firefox coverage/lcov-report/index.html

Coverage

Statements   : 94.05% ( 174/185 )
Branches     : 89.90% ( 89/99 )
Functions    : 100%   ( 21/21 )

Keywords

FAQs

Package last updated on 02 Jun 2015

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