Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromstreamich/memfs

In-memory filesystem with Node's API

License

NotificationsYou must be signed in to change notification settings

forabi/memfs

 
 

In-memory file-system withNode'sfs API.

  • 100% of Node'sfs API implemented, seeAPI Status
  • Stores files in memory, inBuffers
  • Throws same* errors as Node.js
  • Has concept ofi-nodes
  • Implementshard links
  • Implementssoft links (aka symlinks, symbolic links)
  • More testing coming soon*
  • Permissions may* be implemented in the future
  • Can be used in browser, seememfs-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';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

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'sfs module andrequire function
  • libfs - real filesystem (that executes UNIX system calls) implemented in JavaScript

Dependencies

This package depends on the following Node modules:buffer,events,streams,path.

It also usesprocess andsetImmediate globals, but mocks them, if notavailable.

License

Unlicense - public domain.

About

In-memory filesystem with Node's API

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript93.4%
  • JavaScript6.6%

[8]ページ先頭

©2009-2025 Movatter.jp