# normalized-fs

> A drop-in replacement for fs that normalizes its behavior

Latest version **1.0.0-alpha.1** (published 2019-01-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install normalized-fs
pnpm add normalized-fs
yarn add normalized-fs
bun add normalized-fs
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-alpha.1 |
| Published | 2019-01-24 |
| First published | 2019-01-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 346.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Marcus Ekwall |
| Maintainers | mekwall |
| Keywords | fs, module, reading, retry, retries, queue, error, errors, handling, EMFILE, EAGAIN, EINVAL, EPERM, EACCESS |

## Links

- npm: https://www.npmjs.com/package/normalized-fs
- Repository: https://github.com/mekwall/normalized-fs
- Homepage: https://github.com/mekwall/normalized-fs#readme
- Issues: https://github.com/mekwall/normalized-fs/issues
- npm.io page: https://npm.io/package/normalized-fs

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.0.0-alpha.1 (latest) — 2019-01-24
- 1.0.0-alpha.2 (alpha) — 2019-01-24

## README

# normalized-fs

[![GitHub license](https://img.shields.io/badge/license-ISC-blue.svg?style=flat-square)](https://github.com/mekwall/normalized-fs/blob/master/LICENSE)
[![Build Status](https://img.shields.io/circleci/project/github/mekwall/normalized-fs.svg?style=flat-square)](https://circleci.com/gh/mekwall/normalized-fs)
[![Coverage](https://img.shields.io/codecov/c/github/mekwall/normalized-fs/master.svg?style=flat-square)](https://codecov.io/github/mekwall/normalized-fs?branch=master)
[![Dependencies](https://img.shields.io/librariesio/github/mekwall/normalized-fs.svg?style=flat-square)](https://github.com/mekwall/normalized-fs)

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.

## Improvements over [fs module](https://nodejs.org/api/fs.html)

- 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.

## Installation

### npm

```bash
$ npm install normalized-fs
```

### yarn

```bash
$ yarn add normalized-fs
```

## Usage

```typescript
// import just like with fs
import fs from 'normalized-fs';

// now go and do stuff with it...
fs.readFileSync('some-file-or-whatever');
```

## Global patching

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 `EMFILE` errors 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.

```typescript
import realFs from 'fs';
import nfs from 'normalized-fs';
nfs.normalize(realFs);
```

## Credits

Big thanks to [isaacs](https://github.com/isaacs) who created [graceful-fs](https://github.com/isaacs/node-graceful-fs) which this package is based upon.

---
_Source: https://npm.io/package/normalized-fs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
