Socket
Socket
Sign inDemoInstall

memfs

Package Overview
Dependencies
11
Maintainers
1
Versions
145
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    memfs

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


Version published
Maintainers
1
Created

Package description

What is memfs?

The memfs npm package is an in-memory filesystem that mimics the Node.js fs module. It allows you to create an ephemeral file system that resides entirely in memory, without touching the actual disk. This can be useful for testing, mocking, and various other scenarios where you don't want to perform I/O operations on the real file system.

What are memfs's main functionalities?

Creating and manipulating files

This feature allows you to create, read, and write files in memory as if you were using the native fs module.

const { Volume } = require('memfs');
const vol = new Volume();
vol.writeFileSync('/hello.txt', 'Hello, World!');
const content = vol.readFileSync('/hello.txt', 'utf8');
console.log(content); // Outputs: Hello, World!

Directory operations

This feature enables you to create directories, list their contents, and perform other directory-related operations, all in memory.

const { Volume } = require('memfs');
const vol = new Volume();
vol.mkdirSync('/mydir');
vol.writeFileSync('/mydir/file.txt', 'My file content');
const files = vol.readdirSync('/mydir');
console.log(files); // Outputs: ['file.txt']

Linking and symlinking

This feature allows you to create hard links and symbolic links, mimicking the behavior of links on a real file system.

const { Volume } = require('memfs');
const vol = new Volume();
vol.writeFileSync('/original.txt', 'Content of original');
vol.linkSync('/original.txt', '/link.txt');
vol.symlinkSync('/original.txt', '/symlink.txt');
const linkContent = vol.readFileSync('/link.txt', 'utf8');
const symlinkContent = vol.readlinkSync('/symlink.txt');
console.log(linkContent); // Outputs: Content of original
console.log(symlinkContent); // Outputs: /original.txt

File system watching

This feature provides the ability to watch for changes in the file system, similar to fs.watch in the native fs module.

const { Volume } = require('memfs');
const vol = new Volume();
const fs = vol.promises;

async function watchExample() {
  await fs.writeFile('/watched.txt', 'Initial content');
  fs.watch('/watched.txt', (eventType, filename) => {
    console.log(`Event type: ${eventType}; File: ${filename}`);
  });
  await fs.writeFile('/watched.txt', 'Updated content');
}

watchExample();

Other packages similar to memfs

Changelog

Source

4.1.0-next.1 (2023-06-21)

Bug Fixes

  • ๐Ÿ› allow readin into various kinds of buffers (361812d)
  • ๐Ÿ› allow readin into various kinds of buffers (e9c70e9)
  • ๐Ÿ› allow to seek in file (c04895b)
  • ๐Ÿ› allow to seek in file (b363689)
  • ๐Ÿ› do not allow empty children names (f014fd8)
  • ๐Ÿ› do not allow empty children names (43da1d6)
  • ๐Ÿ› handle root folder better (89bbffd)
  • ๐Ÿ› handle root folder better (76de780)
  • ๐Ÿ› throw "ENOENT" and "ENOTDIR" when folder or file 404 (5de4faa)
  • ๐Ÿ› throw "ENOENT" and "ENOTDIR" when folder or file 404 (ddd5d56)

Features

  • ๐ŸŽธ add .truncate() method (038ab36)
  • ๐ŸŽธ add .truncate() method (085335c)
  • ๐ŸŽธ add ability to close files (0db56be)
  • ๐ŸŽธ add ability to close files (d3828a8)
  • ๐ŸŽธ add ability to create sub directories (8f15bd9)
  • ๐ŸŽธ add ability to create sub directories (528c807)
  • ๐ŸŽธ add ability to remove all files (76cabc7)
  • ๐ŸŽธ add ability to remove all files (566e29b)
  • ๐ŸŽธ add appendFileSync() method (57192fe)
  • ๐ŸŽธ add appendFileSync() method (27411e4)
  • ๐ŸŽธ add basenem() utility (8b27695)
  • ๐ŸŽธ add basenem() utility (43354e5)
  • ๐ŸŽธ add copyFile() method (de2bb0a)
  • ๐ŸŽธ add copyFile() method (5e207c4)
  • ๐ŸŽธ add copyFileSync() method (7e0137c)
  • ๐ŸŽธ add copyFileSync() method (5fc1bac)
  • ๐ŸŽธ add createSwapFile() method (dfdb908)
  • ๐ŸŽธ add createSwapFile() method (b07ce79)
  • ๐ŸŽธ add crudfs types (18c0658)
  • ๐ŸŽธ add existsSync() method (0492a98)
  • ๐ŸŽธ add existsSync() method (073ec6b)
  • ๐ŸŽธ add fstatSync() method (f13ddb7)
  • ๐ŸŽธ add fstatSync() method (6b1597a)
  • ๐ŸŽธ add initial writign implementation (2f9542c)
  • ๐ŸŽธ add initial writign implementation (6a50382)
  • ๐ŸŽธ add lstat() and fstat() methods (ce5dd5e)
  • ๐ŸŽธ add lstat() and fstat() methods (e147d58)
  • ๐ŸŽธ add mkdirSync() method (57f386b)
  • ๐ŸŽธ add mkdirSync() method (bcad970)
  • ๐ŸŽธ add mkdtempSync() method (1ac2df4)
  • ๐ŸŽธ add mkdtempSync() method (68033dd)
  • ๐ŸŽธ add options to promises.rmdir() method (ce268bb)
  • ๐ŸŽธ add options to promises.rmdir() method (0628d56)
  • ๐ŸŽธ add pathToLocation() utility (8e0136a)
  • ๐ŸŽธ add pathToLocation() utility (cb92a99)
  • ๐ŸŽธ add read/write mode separation (b4b6fcb)
  • ๐ŸŽธ add read/write mode separation (60a65c1)
  • ๐ŸŽธ add readdirSync() method (2178a50)
  • ๐ŸŽธ add readdirSync() method (3689abd)
  • ๐ŸŽธ add readlinkSync() method (f398908)
  • ๐ŸŽธ add readlinkSync() method (8d243a0)
  • ๐ŸŽธ add readSync() method (31383a8)
  • ๐ŸŽธ add readSync() method (3729cd0)
  • ๐ŸŽธ add realpathSync() method (f9a3cbe)
  • ๐ŸŽธ add realpathSync() method (75890e0)
  • ๐ŸŽธ add renameSync() method (a1674e4)
  • ๐ŸŽธ add renameSync() method (5b1cd63)
  • ๐ŸŽธ add rm() method (239437d)
  • ๐ŸŽธ add rm() method (29a7dc8)
  • ๐ŸŽธ add rmdirSync() method (59ccf3c)
  • ๐ŸŽธ add rmdirSync() method (695b62a)
  • ๐ŸŽธ add rmSync() method (a39e9a2)
  • ๐ŸŽธ add rmSync() method (aa9acb3)
  • ๐ŸŽธ add some common objects (b68ea2a)
  • ๐ŸŽธ add some common objects (c89744d)
  • ๐ŸŽธ add sync api (29c035a)
  • ๐ŸŽธ add sync api (16d6600)
  • ๐ŸŽธ add timeout to spin lock (1e2fc72)
  • ๐ŸŽธ add timeout to spin lock (48e8e74)
  • ๐ŸŽธ add truncateSync() and ftruncateSync() methods (4caf28b)
  • ๐ŸŽธ add truncateSync() and ftruncateSync() methods (2b77619)
  • ๐ŸŽธ add typed array view support to volume (a8bee73)
  • ๐ŸŽธ add typed array view support to volume (7c8439f)
  • ๐ŸŽธ add unlinkSync() method (4b3444d)
  • ๐ŸŽธ add unlinkSync() method (417f911)
  • ๐ŸŽธ add writev() method (17b0446)
  • ๐ŸŽธ add writev() method (8190bfd)
  • ๐ŸŽธ create FSA types folder (c153506)
  • ๐ŸŽธ create FSA types folder (bb0c75a)
  • ๐ŸŽธ create Node fs api tyeps (27fd08a)
  • ๐ŸŽธ create Node fs api tyeps (4db1321)
  • ๐ŸŽธ explose FSA from index file (6865a05)
  • ๐ŸŽธ explose FSA from index file (77696f5)
  • ๐ŸŽธ implement .del() method (9a7fd37)
  • ๐ŸŽธ implement .drop() method (1b893a2)
  • ๐ŸŽธ implement .get() method (63aacb6)
  • ๐ŸŽธ implement .getDirectoryHandle() method (b6b026a)
  • ๐ŸŽธ implement .getDirectoryHandle() method (090980c)
  • ๐ŸŽธ implement .getFile() method (b8601cc)
  • ๐ŸŽธ implement .getFile() method (17015a3)
  • ๐ŸŽธ implement .getFileHandle() method (71567c9)
  • ๐ŸŽธ implement .getFileHandle() method (40bdc13)
  • ๐ŸŽธ implement .isSameEntry() method (f18d91e)
  • ๐ŸŽธ implement .isSameEntry() method (438806b)
  • ๐ŸŽธ implement .list() method (4a064cf)
  • ๐ŸŽธ implement .mkdir method (2623049)
  • ๐ŸŽธ implement .mkdir method (be1525a)
  • ๐ŸŽธ implement .mkdtemp() method (cd54e9b)
  • ๐ŸŽธ implement .mkdtemp() method (2db4cd0)
  • ๐ŸŽธ implement .removeEntry() method (48617aa)
  • ๐ŸŽธ implement .removeEntry() method (dca57a2)
  • ๐ŸŽธ implement .resolve() method (bf47b96)
  • ๐ŸŽธ implement .resolve() method (9d5669c)
  • ๐ŸŽธ implement .values() and .entries() (f13de3b)
  • ๐ŸŽธ implement .values() and .entries() (177010a)
  • ๐ŸŽธ implement .write() for FSA (8226541)
  • ๐ŸŽธ implement .write() for FSA (6a2fa2d)
  • ๐ŸŽธ implement access() method (0a43a1b)
  • ๐ŸŽธ implement access() method (c72390b)
  • ๐ŸŽธ implement accessSync() method (accebdb)
  • ๐ŸŽธ implement accessSync() method (719a19f)
  • ๐ŸŽธ implement basic readdir (898e221)
  • ๐ŸŽธ implement basic readdir (685bc7e)
  • ๐ŸŽธ implement basic rename() method, only for files (169662a)
  • ๐ŸŽธ implement basic rename() method, only for files (4769314)
  • ๐ŸŽธ implement basic state() method (425cad7)
  • ๐ŸŽธ implement basic state() method (4039d64)
  • ๐ŸŽธ implement closeSync() method (24841fa)
  • ๐ŸŽธ implement closeSync() method (646efaf)
  • ๐ŸŽธ implement crudfs .put() method (505dc20)
  • ๐ŸŽธ implement Dirent listings (03e60d0)
  • ๐ŸŽธ implement Dirent listings (5d6f976)
  • ๐ŸŽธ implement exists() method (615e88f)
  • ๐ŸŽธ implement exists() method (0753937)
  • ๐ŸŽธ implement first version of readFile() method (e046128)
  • ๐ŸŽธ implement first version of readFile() method (629f22a)
  • ๐ŸŽธ implement first version of worker (3662003)
  • ๐ŸŽธ implement first version of worker (caf8394)
  • ๐ŸŽธ implement FSA ReadStream (bc50fc5)
  • ๐ŸŽธ implement FSA ReadStream (53784d9)
  • ๐ŸŽธ implement info() method (eea9215)
  • ๐ŸŽธ implement initial version of .open() mehtod (b3983df)
  • ๐ŸŽธ implement initial version of .open() mehtod (cb363b5)
  • ๐ŸŽธ implement initial version of appendFile() method (616be8d)
  • ๐ŸŽธ implement initial version of appendFile() method (65580aa)
  • ๐ŸŽธ implement initial version of writeFile() method (80e8499)
  • ๐ŸŽธ implement initial version of writeFile() method (e2b2bfd)
  • ๐ŸŽธ implement keys() method (33f9af0)
  • ๐ŸŽธ implement keys() method (b8e8a4c)
  • ๐ŸŽธ implement openSync() method (8ecac69)
  • ๐ŸŽธ implement openSync() method (4b7eddd)
  • ๐ŸŽธ implement read() method (33bea4b)
  • ๐ŸŽธ implement read() method (7357c14)
  • ๐ŸŽธ implement readFileSync() method (3a1b737)
  • ๐ŸŽธ implement readFileSync() method (2a07e34)
  • ๐ŸŽธ implement readFileSync() method (953d276)
  • ๐ŸŽธ implement readFileSync() method (bb803e2)
  • ๐ŸŽธ implement realpath() method (458a7b2)
  • ๐ŸŽธ implement realpath() method (99b12dc)
  • ๐ŸŽธ implement rmdir() method (c06734b)
  • ๐ŸŽธ implement rmdir() method (973af0a)
  • ๐ŸŽธ implement sync messenger (1c0bd59)
  • ๐ŸŽธ implement sync messenger (d221870)
  • ๐ŸŽธ implement sync write method (3017ecd)
  • ๐ŸŽธ implement sync write method (22047da)
  • ๐ŸŽธ implement truncation (af8452e)
  • ๐ŸŽธ implement truncation (d4469d1)
  • ๐ŸŽธ implement unlink() method (e11a383)
  • ๐ŸŽธ implement unlink() method (6bd3e75)
  • ๐ŸŽธ implement writeSync() method (7a2fced)
  • ๐ŸŽธ implement writeSync() method (12a8b3f)
  • ๐ŸŽธ improve mkdir method (e6dd59e)
  • ๐ŸŽธ improve mkdir method (c393f6c)
  • ๐ŸŽธ improve read stream interfaces (7e1a844)
  • ๐ŸŽธ improve read stream interfaces (6d5de0c)
  • ๐ŸŽธ improve stat method (505a1d9)
  • ๐ŸŽธ improve stat method (c6eeab4)
  • ๐ŸŽธ improve write stream, better flag handling (531f2a7)
  • ๐ŸŽธ improve write stream, better flag handling (7b9e0a3)
  • ๐ŸŽธ improve writing at offset logic (71b6afc)
  • ๐ŸŽธ improve writing at offset logic (392932a)
  • ๐ŸŽธ improve writing to file (1de0e06)
  • ๐ŸŽธ improve writing to file (3edcac1)
  • ๐ŸŽธ include "writeSync" method for sync writer (b267f78)
  • ๐ŸŽธ include "writeSync" method for sync writer (b006b2d)
  • ๐ŸŽธ introduce FSA context (f603262)
  • ๐ŸŽธ introduce FSA context (b696e09)
  • ๐ŸŽธ make basic WriteStream work (69281ff)
  • ๐ŸŽธ make basic WriteStream work (c109af1)
  • ๐ŸŽธ make statSync() resolve the path correctly (0d81728)
  • ๐ŸŽธ make statSync() resolve the path correctly (7801533)
  • ๐ŸŽธ normalize adapter rpc (16ce2cf)
  • ๐ŸŽธ normalize adapter rpc (96b8374)
  • ๐ŸŽธ progress on writable stream (a568afd)
  • ๐ŸŽธ progress on writable stream (9900423)
  • ๐ŸŽธ setup fsa to node utility (50d2a1e)
  • ๐ŸŽธ setup fsa to node utility (5fa0d61)
  • ๐ŸŽธ setup node-to-fsa folder (a4268c6)
  • ๐ŸŽธ setup node-to-fsa folder (16e78e3)
  • ๐ŸŽธ setup webfs (68f0014)
  • ๐ŸŽธ setup webfs (99c915f)
  • ๐ŸŽธ standartize message contents (b3254f6)
  • ๐ŸŽธ standartize message contents (c254dc7)
  • ๐ŸŽธ start synchronous file handle implementation (f9b0f73)
  • ๐ŸŽธ start synchronous file handle implementation (d05c407)
  • ๐ŸŽธ start WriteStream implementation (5971c39)
  • ๐ŸŽธ start WriteStream implementation (32e13a8)
  • ๐ŸŽธ throw exception on closed files (7adff27)
  • ๐ŸŽธ throw exception on closed files (5119b8f)
  • ๐ŸŽธ track number of written bytes (b80f7b7)
  • ๐ŸŽธ track number of written bytes (7a65daa)
  • ๐ŸŽธ write through a swap file (84cecec)
  • ๐ŸŽธ write through a swap file (5134766)

Readme

Source

memfs

JavaScript file system utilities for Node.js and browser.

Install

npm i memfs

Docs

Demos

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

License

Apache 2.0

Keywords

FAQs

Last updated on 21 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc