Skip to content

Latest commit

History

49 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Filequeue

Drop-in Replacement for fs that avoids Error: EMFILE, too many open files.

As of version 0.4.0, Filequeue supports Node 0.10.x, and as of version 0.5.0, it has basic Streams support.

Filequeue was born out of my encounter with Error: EMFILE, too many open files, which occurs when you try to open too many files at once on your system. Due to Node's asynchronous nature, if you perform a lot of fs.readFile or similar operations in quick succession, you can easily hit your system's maxfiles limit, usually set to 256 on a dev box.

Filequeue creates a replacement for fs, that I use as fq with many of the same operations. However, it keeps track of how many files are open at once, and queues them if there are too many.

Installation

Through NPM

$ npm install filequeue

or using Git

$ git clone git://github.com/treygriffith/filequeue.git node_modules/filequeue/

How to Use

Instantiate Filequeue with a maximum number of files to be opened at once (default is 200)

varFileQueue=require('filequeue');varfq=newFileQueue(100);// additional instances will attempt to use the same instance (and therefore the same maxfiles)varFileQueue2=require('filequeue');varfq2=newFileQueue2(100);console.log(fq===fq2);// => true// you can force a new instance of filequeue with the `newQueue` parametervarfq3=newFileQueue(100,true);console.log(fq===fq3);// => false

Use any of the following supported fs methods

for(vari=0;i<1000;i++){fq.readFile('/somefile.txt',{encoding: 'utf8'},function(err,somefile){console.log("data from somefile.txt without crashing!",somefile);});}

Other Methods

Adding a new fs method is simple, just add it to the methods.js file following the conventions therein.

Pull requests to add other fs methods with tests exercising them are welcome.

About

Drop-in Replacement for `fs` that avoids `Error: EMFILE, too many open files`

Resources

Stars

28 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages