Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork139
Node.js "fs" and browser "File System API" adapters and in-memory implementations 👍
License
NotificationsYou must be signed in to change notification settings
streamich/memfs
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
In-memory file-system withNode'sfs API.
- Node's
fsAPI implemented, seeAPI Status - Stores files in memory, in
Buffers - Throws sameish* errors as Node.js
- Has concept ofi-nodes
- Implementshard links
- Implementssoft links (aka symlinks, symbolic links)
- Permissions may* be implemented in the future
- Can be used in browser, see
memfs-webpack
npm install --save memfs
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';constjson={'./README.md':'1','./src/index.js':'2','./node_modules/debug/index.js':'3',};vol.fromJSON(json,'/app');fs.readFileSync('/app/README.md','utf8');// 1vol.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';constvol=Volume.fromJSON({'/foo':'bar'});vol.readFileSync('/foo');// barconstvol2=Volume.fromJSON({'/foo':'bar 2'});vol2.readFileSync('/foo');// bar 2
Usememfs together withunionfs to create one filesystemfrom your in-memory volumes and the real disk filesystem:
import*asfsfrom'fs';import{ufs}from'unionfs';ufs.use(fs).use(vol);ufs.readFileSync('/foo');// bar
Usefs-monkey to monkey-patch Node'srequire function:
import{patchRequire}from'fs-monkey';vol.writeFileSync('/index.js','console.log("hi world")');patchRequire(vol);require('/index');// hi world
spyfs- spies on filesystem actionsunionfs- creates a union of multiple filesystem volumeslinkfs- redirects filesystem pathsfs-monkey- monkey-patches Node'sfsmodule andrequirefunctionlibfs- real filesystem (that executes UNIX system calls) implemented in JavaScript
Unlicense - public domain.
About
Node.js "fs" and browser "File System API" adapters and in-memory implementations 👍
Topics
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.