🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

@researchgate/file-processor

Package Overview
Dependencies
Maintainers
9
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@researchgate/file-processor

Run parallel tasks on a multiple files

latest
Source
npmnpm
Version
3.2.0
Version published
Weekly downloads
51
-47.42%
Maintainers
9
Weekly downloads
 
Created
Source

file-processor

Build Status codecov

Node.js utility for mass-processing files in parallel.

Usage

Files are handled in parallel running workers. In order to use the library you need 2 modules.

Worker module

Must export single function, accepting fileName and callback. This function must process the file and call the callback when it is done. Function can be asynchronous.

module.exports = function (fileName, callback) {
  const result = doExpensiveProcessing(fileName);
  callback(null, result);
};

Main module

Must use FileProcessor class and provide a it one or more glob patterns and path to worker module. Each file, matching the pattern will be processed by worker module.

const FileProcessor = require('@researchgate/file-processor');
const processor = new FileProcessor(
  ['path/to/some/files/*.txt', 'some/other/path/*.js'],
  require.resolve('./worker')
);

processor.on('processed', (fileName, result) => {
  console.log(`result for ${fileName}: ${result}`);
});

FileProcessor instace emits following events:

  • queued - file is queued for processing.

    Arguments:

    • fileName
  • processed - file is successfully processed by worker.

    Arguments:

    • fileName
    • result - the result, returned by worker module
  • error - worker failed to process the file

    Arguments:

    • error
  • allQueued - all files, matching the pattern are queued for processing.

    Arguments:

    • stats - object with the following field

      • queuedCount - total number of queued files
      • processedCount - total number of files which are already processed
  • end - all files are processed.

FAQs

Package last updated on 22 Dec 2020

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