memfs
In-memory file-system with Node's fs API.
Last updated 6 days ago by streamich .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install memfs 
SYNC missed versions from official npm registry.

memfs

In-memory file-system with Node's fs API.

  • Node's fs API implemented, see API Status
  • Stores files in memory, in Buffers
  • Throws sameish* errors as Node.js
  • Has concept of i-nodes
  • Implements hard links
  • Implements soft links (aka symlinks, symbolic links)
  • Permissions may* be implemented in the future
  • Can be used in browser, see memfs-webpack

Install

npm install --save memfs

Usage

import { fs } from 'memfs';

fs.writeFileSync('/hello.txt', 'World!');
fs.readFileSync('/hello.txt', 'utf8'); // World!

Create a file system from a plain JSON:

import { fs, vol } from 'memfs';

const json = {
  './README.md': '1',
  './src/index.js': '2',
  './node_modules/debug/index.js': '3',
};
vol.fromJSON(json, '/app');

fs.readFileSync('/app/README.md', 'utf8'); // 1
vol.readFileSync('/app/src/index.js', 'utf8'); // 2

Export to JSON:

vol.writeFileSync('/script.sh', 'sudo rm -rf *');
vol.toJSON(); // {"/script.sh": "sudo rm -rf *"}

Use it for testing:

vol.writeFileSync('/foo', 'bar');
expect(vol.toJSON()).toEqual({ '/foo': 'bar' });

Create as many filesystem volumes as you need:

import { Volume } from 'memfs';

const vol = Volume.fromJSON({ '/foo': 'bar' });
vol.readFileSync('/foo'); // bar

const vol2 = Volume.fromJSON({ '/foo': 'bar 2' });
vol2.readFileSync('/foo'); // bar 2

Use memfs together with unionfs to create one filesystem from your in-memory volumes and the real disk filesystem:

import * as fs from 'fs';
import { ufs } from 'unionfs';

ufs.use(fs).use(vol);

ufs.readFileSync('/foo'); // bar

Use fs-monkey to monkey-patch Node's require function:

import { patchRequire } from 'fs-monkey';

vol.writeFileSync('/index.js', 'console.log("hi world")');
patchRequire(vol);
require('/index'); // hi world

Docs

See also

  • spyfs - spies on filesystem actions
  • unionfs - creates a union of multiple filesystem volumes
  • linkfs - redirects filesystem paths
  • fs-monkey - monkey-patches Node's fs module and require function
  • libfs - real filesystem (that executes UNIX system calls) implemented in JavaScript

License

Unlicense - public domain.

Current Tags

  • 3.1.1                                ...           latest (6 days ago)

84 Versions

  • 3.1.1                                ...           6 days ago
  • 3.1.0                                ...           6 days ago
  • 3.0.6                                ...           8 days ago
  • 3.0.5                                ...           8 days ago
  • 3.0.4                                ...           a month ago
  • 3.0.3                                ...           2 months ago
  • 3.0.2                                ...           2 months ago
  • 3.0.1                                ...           3 months ago
  • 3.0.0                                ...           3 months ago
  • 2.17.1                                ...           3 months ago
  • 2.17.0                                ...           3 months ago
  • 2.16.1                                ...           4 months ago
  • 2.16.0 [deprecated]           ...           4 months ago
  • 2.15.5                                ...           7 months ago
  • 2.15.4                                ...           9 months ago
  • 2.15.3                                ...           9 months ago
  • 2.15.2                                ...           a year ago
  • 2.15.1                                ...           a year ago
  • 2.15.0                                ...           a year ago
  • 2.14.2                                ...           a year ago
  • 2.14.1                                ...           a year ago
  • 2.14.0                                ...           a year ago
  • 2.13.1                                ...           a year ago
  • 2.13.0                                ...           a year ago
  • 2.12.1                                ...           a year ago
  • 2.12.0                                ...           a year ago
  • 2.11.0                                ...           a year ago
  • 2.10.1                                ...           a year ago
  • 2.10.0                                ...           a year ago
  • 2.9.4                                ...           2 years ago
  • 2.9.3                                ...           2 years ago
  • 2.9.2                                ...           2 years ago
  • 2.9.1                                ...           2 years ago
  • 2.9.0                                ...           2 years ago
  • 2.8.0                                ...           2 years ago
  • 2.7.1                                ...           2 years ago
  • 2.7.0                                ...           2 years ago
  • 2.5.12                                ...           2 years ago
  • 2.5.11                                ...           2 years ago
  • 2.6.2                                ...           2 years ago
  • 2.6.1                                ...           2 years ago
  • 2.6.0                                ...           2 years ago
  • 2.5.10                                ...           2 years ago
  • 2.5.9                                ...           2 years ago
  • 2.5.8                                ...           2 years ago
  • 2.5.7                                ...           2 years ago
  • 2.5.6                                ...           2 years ago
  • 2.5.5                                ...           2 years ago
  • 2.5.4                                ...           2 years ago
  • 2.5.3                                ...           2 years ago
  • 2.5.0                                ...           2 years ago
  • 2.4.1                                ...           2 years ago
  • 2.4.0                                ...           2 years ago
  • 2.3.0                                ...           2 years ago
  • 2.2.0                                ...           2 years ago
  • 2.1.2                                ...           3 years ago
  • 2.1.1                                ...           3 years ago
  • 2.1.0                                ...           3 years ago
  • 2.0.11                                ...           3 years ago
  • 2.0.10                                ...           3 years ago
  • 2.0.9                                ...           3 years ago
  • 2.0.8                                ...           3 years ago
  • 2.0.7                                ...           3 years ago
  • 2.0.6                                ...           3 years ago
  • 2.0.5                                ...           3 years ago
  • 2.0.4                                ...           3 years ago
  • 2.0.3                                ...           3 years ago
  • 2.0.2                                ...           3 years ago
  • 2.0.1                                ...           3 years ago
  • 0.0.15                                ...           3 years ago
  • 0.0.14                                ...           3 years ago
  • 0.0.13                                ...           3 years ago
  • 0.0.12                                ...           3 years ago
  • 0.0.11                                ...           3 years ago
  • 0.0.10                                ...           3 years ago
  • 0.0.9                                ...           4 years ago
  • 0.0.8                                ...           4 years ago
  • 0.0.7                                ...           4 years ago
  • 0.0.6                                ...           5 years ago
  • 0.0.5                                ...           5 years ago
  • 0.0.4                                ...           5 years ago
  • 0.0.3                                ...           5 years ago
  • 0.0.2                                ...           5 years ago
  • 0.0.1                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 3,687
Last Day 91
Last Week 2,530
Last Month 1,008
Dependencies (1)
Dev Dependencies (17)
Dependents (98)

Copyright 2014 - 2016 © taobao.org |