In-memory filesystem with Node's API (forked from upstream memfs since there are longstanding bugs)
Installations
npm install @cowasm/memfs
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>= 4.0.0
Node Version
19.0.0
NPM Version
8.19.2
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (99.9%)
JavaScript (0.1%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
69,418
Last Day
2
Last Week
2
Last Month
2,050
Last Year
33,775
GitHub Statistics
2 Stars
1,044 Commits
4 Watching
1 Branches
Bundle Size
49.87 kB
Minified
15.26 kB
Minified + Gzipped
Package Meta Information
Latest Version
3.5.1
Package Id
@cowasm/memfs@3.5.1
Unpacked Size
154.46 kB
Size
35.09 kB
File Count
32
NPM Version
8.19.2
Node Version
19.0.0
Total Downloads
Cumulative downloads
Total Downloads
69,418
Last day
0%
2
Compared to previous day
Last week
-99.6%
2
Compared to previous week
Last month
-19%
2,050
Compared to previous month
Last year
1.5%
33,775
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
memfs
This is a fork of https://www.npmjs.com/package/memfs, since there's a bunch of critical bugs and missing maintenance there, which might not be a priority for that project, but are definitely a priority for me (though I'm sending PR's). Upstream memfs has nearly 12 million downloads a week, so I can see why doing these changes would be really scary there!
Things I've done here include:
- update to newest jest, and increase maxWorkers for testing; fix an issue with one test
- update to newest typescript and node typings
- update target to es2020 from es5; this does make code run more efficiently and is much easier to debug if you want to directly edit node_modules
- fix the 13 security vulnerabilities revealed by npm audit
- upgrade prettier and switch to using the defaults
- switch to package-lock.json instead of yarn's lock
- fix chmodSync bug
- fix utimesSync bug
- fix realpathSync bug
See https://github.com/sagemathinc/memfs-js
Upstream description
In-memory file-system with Node's fs
API.
- Node's
fs
API implemented, see old API Status, missing list, missingopendir
- 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
1npm install --save memfs
Usage
1import { fs } from "memfs"; 2 3fs.writeFileSync("/hello.txt", "World!"); 4fs.readFileSync("/hello.txt", "utf8"); // World!
Create a file system from a plain JSON:
1import { fs, vol } from "memfs"; 2 3const json = { 4 "./README.md": "1", 5 "./src/index.js": "2", 6 "./node_modules/debug/index.js": "3", 7}; 8vol.fromJSON(json, "/app"); 9 10fs.readFileSync("/app/README.md", "utf8"); // 1 11vol.readFileSync("/app/src/index.js", "utf8"); // 2
Export to JSON:
1vol.writeFileSync("/script.sh", "sudo rm -rf *"); 2vol.toJSON(); // {"/script.sh": "sudo rm -rf *"}
Use it for testing:
1vol.writeFileSync("/foo", "bar"); 2expect(vol.toJSON()).toEqual({ "/foo": "bar" });
Create as many filesystem volumes as you need:
1import { Volume } from "memfs";
2
3const vol = Volume.fromJSON({ "/foo": "bar" });
4vol.readFileSync("/foo"); // bar
5
6const vol2 = Volume.fromJSON({ "/foo": "bar 2" });
7vol2.readFileSync("/foo"); // bar 2
Use memfs
together with unionfs
to create one filesystem
from your in-memory volumes and the real disk filesystem:
1import * as fs from "fs"; 2import { ufs } from "unionfs"; 3 4ufs.use(fs).use(vol); 5 6ufs.readFileSync("/foo"); // bar
Use fs-monkey
to monkey-patch Node's require
function:
1import { patchRequire } from "fs-monkey"; 2 3vol.writeFileSync("/index.js", 'console.log("hi world")'); 4patchRequire(vol); 5require("/index"); // 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.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No security vulnerabilities found.