Socket
Socket
Sign inDemoInstall

memory-fs

Package Overview
Dependencies
10
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

memory-fs

A simple in-memory filesystem. Holds data in a javascript object.

    0.5.0latest
    GitHub
    npm

Version published
Maintainers
1
Weekly downloads
14,744,101
increased by3.35%

Weekly downloads

Package description

What is memory-fs?

The memory-fs npm package is an in-memory filesystem that mimics the Node.js fs module. It allows you to create, read, write, and delete files and directories in memory, which can be useful for testing or when you need a temporary filesystem that does not interact with the actual disk.

What are memory-fs's main functionalities?

Creating and writing files

This feature allows you to create new files and write content to them, similar to fs.writeFileSync in Node.js.

{"const MemoryFS = require('memory-fs');\nconst fs = new MemoryFS();\nfs.writeFileSync('/my-file.txt', 'Hello World');"}

Reading files

This feature allows you to read the contents of files that exist in the in-memory filesystem.

{"const MemoryFS = require('memory-fs');\nconst fs = new MemoryFS();\nfs.writeFileSync('/my-file.txt', 'Hello World');\nconst content = fs.readFileSync('/my-file.txt', 'utf-8');"}

Creating directories

This feature allows you to create directories within the in-memory filesystem.

{"const MemoryFS = require('memory-fs');\nconst fs = new MemoryFS();\nfs.mkdirSync('/my-directory');"}

Deleting files and directories

This feature allows you to delete files and directories from the in-memory filesystem.

{"const MemoryFS = require('memory-fs');\nconst fs = new MemoryFS();\nfs.writeFileSync('/my-file.txt', 'Hello World');\nfs.unlinkSync('/my-file.txt');\nfs.mkdirSync('/my-directory');\nfs.rmdirSync('/my-directory');"}

Other packages similar to memory-fs

Readme

Source

memory-fs

A simple in-memory filesystem. Holds data in a javascript object.

var MemoryFileSystem = require("memory-fs");
var fs = new MemoryFileSystem(); // Optionally pass a javascript object

fs.mkdirpSync("/a/test/dir");
fs.writeFileSync("/a/test/dir/file.txt", "Hello World");
fs.readFileSync("/a/test/dir/file.txt"); // returns Buffer("Hello World")

// Async variants too
fs.unlink("/a/test/dir/file.txt", function(err) {
	// ...
});

fs.readdirSync("/a/test"); // returns ["dir"]
fs.statSync("/a/test/dir").isDirectory(); // returns true
fs.rmdirSync("/a/test/dir");

fs.mkdirpSync("C:\\use\\windows\\style\\paths");

License

Copyright (c) 2012-2014 Tobias Koppers

MIT (http://www.opensource.org/licenses/mit-license.php)

Keywords

FAQs

Last updated on 08 Oct 2019

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the 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