# virtualfs

> In-memory fs replacement

Latest version **2.2.0** (published 2018-06-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install virtualfs
pnpm add virtualfs
yarn add virtualfs
bun add virtualfs
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2018-06-21 |
| First published | 2017-08-29 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=6.4.0 |
| Dependencies | 6 |
| Unpacked size | 758.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 34 |
| Author | Roger Qiu |
| Maintainers | cmcdragonkai |
| Keywords | fs, memory |

## Links

- npm: https://www.npmjs.com/package/virtualfs
- Repository: https://github.com/MatrixAI/js-virtualfs
- Homepage: https://github.com/MatrixAI/js-virtualfs#readme
- Issues: https://github.com/MatrixAI/js-virtualfs/issues
- npm.io page: https://npm.io/package/virtualfs

## Dependencies (6)

- [errno](https://npm.io/package/errno.md) ^0.1.7
- [permaproxy](https://npm.io/package/permaproxy.md) 0.0.2
- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.26.0
- [readable-stream](https://npm.io/package/readable-stream.md) ^2.3.6
- [resource-counter](https://npm.io/package/resource-counter.md) ^1.2.4
- [secure-random-bytes](https://npm.io/package/secure-random-bytes.md) ^1.0.1

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

- 2.2.0 (latest) — 2018-06-21
- 2.1.1 — 2018-06-20
- 2.1.0 — 2018-06-03
- 2.0.5 — 2018-05-14
- 2.0.4 — 2018-02-02
- 2.0.3 — 2018-01-31
- 2.0.2 — 2017-11-20
- 2.0.1 — 2017-11-11
- 2.0.0 — 2017-11-11
- 1.0.0 — 2017-08-29
- 0.0.1 — 2017-08-29

## README

# VirtualFS

VirtualFS is a virtual posix-like filesystem that runs completely in memory. It is intended to work in browsers and in NodeJS. For browser usage, make use of a bundler like Webpack, Browserify or Rollup.

It includes:

* Proper stat metadata with MAC time handling
* Symlink support
* Hardlink support
* Virtual inodes
* File descriptor support
* Proper streams implementation
* Character device support (/dev/null, /dev/full, /dev/tty...)
* Current working directory support
* Simulation of Unix file permissions
* Umask is considered when creating new iNodes
* Simulates POSIX filesystem errors
* Emulates `mmap` with `MAP_PRIVATE` and `MAP_SHARED`
* Usage of Flow types
* Removal of all Windows path support
* Practically complete compatibility with Node's FileSystem API

This package will be maintained as long as the Polykey project is maintained. All tests are passing in this fork.

Documentation
--------------

Documentation is located in the `doc` folder. You can also view the [rendered HTML](https://cdn.rawgit.com/MatrixAI/js-virtualfs/64b3d7de/doc/index.html).

The VirtualFS API extends Node's `fs` API, while also leaving out functions that are not emulatable in-memory. For the functions that have the same name, you can just refer to Node's FS API: https://nodejs.org/api/fs.html. For the functions that don't have the name, refer to the generated API documentation that uses flow types. The source code is understandable so you can just read that as well.

To use VirtualFS as a global polyfill for `fs`, all you need to do is:

```js
import vfs from 'virtualfs';
(typeof self === 'undefined' ? typeof global === 'undefined' ? this : global : self).fs = vfs;
// alternatively use the global package `import global from 'global'; global.fs = vfs;`
```

All subsequent uses of `fs` in the current module, subsequently imported modules, and __any module that imports the current module__ will also use the same `fs`. The above monkeypatch works in Node, Browsers and Web Workers. However this will also make `/dev/tty` not work because it uses Node's real `fs`. Instead you should rely on a per-module override. Unless of course you're not using `/dev/tty` in Node.

In order to only override on a per-module basis you'll need to use the rewire package or the https://github.com/speedskater/babel-plugin-rewire babel plugin.

When using this in a CommonJS environment, you can gain access to the default `fs` replacement by using `var fs = require('virtualfs').default;`.

Development
-------------

To run flow type checks:

```
flow status
flow stop
```

To build this package for release:

```
npm run build
```

It will run tests, generate documentation and output multiple targets. One for browsers and one for nodejs. See `rollup.config.js` to see the target specification.

If your bundler is aware of the module field in `package.json`, you'll get the ES6 module directly.

Once you've updated the package run this:

```
npm version <update_type>
npm publish
```

The browser target makes use of these polyfills:

* buffer - Used everywhere.
* events - Used by streams dependency.
* path - Used for `join`.
* process - Used for `nextTick` and `stdin` and `stdout` streams.
* stream - Used for filesystem streaming

They are currently supplied through Rollup plugins.

Todo
-----

* Investigate mounting implementation

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