Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
graceful-fs | 4.1.15 | 8 kB | ISC | prod |
Graceful-fs is a comprehensive software package designed to function as a drop-in replacement for the fs module, or file system module, found in Node.js. It embodies various enhancements that are aimed to standardize the behavior across different operating systems and environments, as well as increase the resilience to errors in file system access. This includes measures like queuing up 'open' and 'readdir' calls, retrying them once something closes if there's an EMFILE error from too many file descriptors, and implementing fs.lutimes if possible. On Windows, it retries renaming a file for up to one second if the 'EACCESS' or 'EPERM' error occurs. This may be because antivirus software has temporarily locked the directory.
Using Graceful-fs is very straightforward. It can be installed using npm and then used just like you would use the fs module. Here's an example of how you might utilize it:
// Using Graceful-fs
var fs = require('graceful-fs');
// Use it to read a file
fs.readFile('some-file-or-whatever', (err, data) => {
// Process the file here.
})
In certain instances, you might want to patch the global fs module. Here's an example of how to handle that:
// Global fs module patching
var realFs = require('fs');
var gracefulFs = require('graceful-fs');
gracefulFs.gracefulify(realFs);
However, it's crucial to remember that patching should only be performed at the top-level application layer to avoid unexpected delays in other parts of the program.
The documentation and additional information for Graceful-fs can be found in the README file in the repository on GitHub. It's located at git+https://github.com/isaacs/node-graceful-fs.git. This documentation outlines the specific improvements that Graceful-fs provides over the standard fs module, gives usage examples, details about global patching, and a variety of other pertinent resources and information. Users familiar with fs module can quickly adapt to the use of Graceful-fs, thanks to the comprehensive information and examples provided in the documentation.