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

safefs

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

safefs

Say goodbye to EMFILE errors! Open only as many files as the operating system supports

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25K
decreased by-79.16%
Maintainers
1
Weekly downloads
 
Created
Source

Safe FS Build Status

Say goodbye to EMFILE errors! Open only as many files as the operating system supports

Install

Backend

  1. Install Node.js
  2. npm install --save safefs

Frontend

  1. See Browserify

Usage

Example

// Import
var safefs = require('safefs');

// Indicate we're wanting to open a file and reserve our space in the queue
// If there is space in the pool, our callback will run right away
// If there isn't space, our callback will fire as soon as there is
safefs.openFile(function(){
	// We just got some available space, lets do our stuff with the file
	require('fs').writeFileSync('some-file', 'data')
	// Once we're done, indicate it, so that other tasks can swim in the pool too
	safefs.closeFile();
});

// If we're working with an asynchronous function, it'll look like this
safefs.openFile(function(){
	require('fs').writeFile('some-file', 'data', function(err){
		safefs.closeFile();
	});
});
// as we only want to close file once we are completely done with it

// However, that's pretty annoying have to wrap all our calls in openFile and closeFile
// so it's a good thing that safefs provides wrappers for all the asynchronous fs methods for us
// allowing us to just do
safefs.writeFile('some-file', 'data', function(err){
	// all done
});
// which will open and close the spot in the pool for us automatically, yay!

Methods

  • Custom methods:
    • openFile(next)
    • closeFile()
  • Wrapped fs/path methods:
    • readFile
    • writeFile
    • appendFile
    • mkdir
    • stat
    • readdir
    • unlink
    • rmdir
    • exists
    • existsSync

Notes

  • You should call openFile before and afterFile after ALL file system interaction
  • To make this possible, we maintain the following globals:
    • numberOfOpenFiles - defaults to 0
    • maxNumberOfOpenFiles - defaults to process.env.NODE_MAX_OPEN_FILES if available, otherwise sets to 100
    • waitingToOpenFileDelay - defaults to 100

History

You can discover the history inside the History.md file

License

Licensed under the incredibly permissive MIT License
Copyright © 2013+ Bevry Pty Ltd
Copyright © 2011-2012 Benjamin Arthur Lupton

Keywords

FAQs

Package last updated on 29 Mar 2013

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