memfs 2.0
In-memory file-system with Node's fs
API.
- Node's
fs
API implemented, see API Status - Stores files in memory, in
Buffer
s - 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
; fs;fs; // World!
Create a file system from a plain JSON:
; const json = './README.md': '1' './src/index.js': '2' './node_modules/debug/index.js': '3';vol; fs; // 1vol; // 2
Export to JSON:
vol;vol; // {"/script.sh": "sudo rm -rf *"}
Use it for testing:
vol;;
Create as many filesystem volumes as you need:
; const vol = Volume;vol; // bar const vol2 = Volume;vol2; // bar 2
Use memfs
together with unionfs
to create one filesystem
from your in-memory volumes and the real disk filesystem:
;; ufs; ufs; // bar
Use fs-monkey
to monkey-patch Node's require
function:
; vol;;; // hi world
Docs
See also
spyfs
- spies on filesystem actionsunionfs
- creates a union of multiple filesystem volumeslinkfs
- redirects filesystem pathsfs-monkey
- monkey-patches Node'sfs
module andrequire
functionlibfs
- real filesystem (that executes UNIX system calls) implemented in JavaScript
License
Unlicense - public domain.