Socket
Socket
Sign inDemoInstall

memory-fs

Package Overview
Dependencies
10
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    memory-fs

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


Version published
Weekly downloads
11M
decreased by-18.31%
Maintainers
1
Install size
222 kB
Created
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 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