Socket
Socket
Sign inDemoInstall

memfs

Package Overview
Dependencies
11
Maintainers
1
Versions
146
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
Weekly downloads
15M
decreased by-2.4%
Maintainers
1
Install size
7.13 MB
Created
Weekly downloads
 

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 (2023-06-26)

Bug Fixes

  • 🐛 add support for unknown nodes (77786f1)
  • 🐛 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)
  • 🐛 correctly handle directory paths (ea909e8)
  • 🐛 do not allow empty children names (f014fd8)
  • 🐛 do not allow empty children names (43da1d6)
  • 🐛 handle root folder better (89bbffd)
  • 🐛 handle root folder better (76de780)
  • 🐛 improve file opening and closing logic (403c271)
  • 🐛 throw "ENOENT" and "ENOTDIR" when folder or file 404 (5de4faa)
  • 🐛 throw "ENOENT" and "ENOTDIR" when folder or file 404 (ddd5d56)

Features

  • 🎸 add .toTree() to Volume (2d5c4cb)
  • 🎸 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 binary serialization to snapshots (c1cd615)
  • 🎸 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 integrity check on read (710eb2f)
  • 🎸 add json encoding for snapshots (41f9b8c)
  • 🎸 add lstat() and fstat() methods (ce5dd5e)
  • 🎸 add lstat() and fstat() methods (e147d58)
  • 🎸 add missing callback API methods and some sycn API ones (956533a)
  • 🎸 add missing promisees API types (f6727f3)
  • 🎸 add missing synchronous method types (ac38b5d)
  • 🎸 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 snapshot creation utilities (9fc8f13)
  • 🎸 add some common objects (b68ea2a)
  • 🎸 add some common objects (c89744d)
  • 🎸 add sumlink printing support (1850dae)
  • 🎸 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 async verions of snapshotting (18912bf)
  • 🎸 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 CAS storage (33ddbcc)
  • 🎸 implement closeSync() method (24841fa)
  • 🎸 implement closeSync() method (646efaf)
  • 🎸 implement crudfs .put() method (505dc20)
  • 🎸 implement crudfs on top of fs (cb7ac4d)
  • 🎸 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 toTreeSync() method (09c9770)
  • 🎸 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 promises methods bound (3010141)
  • 🎸 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 NodeCrud implementation (39073ce)
  • 🎸 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
  • libfs - real filesystem (that executes UNIX system calls) implemented in JavaScript

License

Apache 2.0

Keywords

FAQs

Last updated on 20 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