A drop-in replacement for
fs that aims to normalize the behavior across different platforms and environments, and to make filesystem access more resilient to errors.
- Queues up open and readdir calls, and retries them once something closes if there is an EMFILE error from too many file descriptors.
- Fixes lchmod for Node versions prior to 0.6.2.
- Implements fs.lutimes if possible. Otherwise it becomes a noop.
- Ignores EINVAL and EPERM errors in chown, fchown or lchown if the user isn't root.
- Makes lchmod and lchown become noops, if not available.
- Retries reading a file if read results in EAGAIN error.
$ npm install normalized-fs
$ yarn add normalized-fs
// import just like with fs;// now go and do stuff with it...fs.readFileSync'some-file-or-whatever';
If you want to patch the global fs module (or any other fs-like module) you can do this:
NOTE: This should only ever be done at the top-level application layer, in order to delay on
EMFILEerrors from any fs-using dependencies. You should not do this in a library, because it can cause unexpected delays in other parts of the program.