Socket
Socket
Sign inDemoInstall

fs-monkey

Package Overview
Dependencies
0
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fs-monkey

Monkey patches for file system related things.


Version published
Weekly downloads
14M
increased by3.5%
Maintainers
1
Install size
21.5 kB
Created
Weekly downloads
 

Package description

What is fs-monkey?

The fs-monkey package is a utility library for Node.js that allows you to patch or virtualize the Node.js file system (fs) module. This can be particularly useful for testing purposes, where you might want to avoid performing I/O operations on the actual file system. It provides functionalities to patch the global fs module, or to create a virtual file system that can be used independently.

What are fs-monkey's main functionalities?

Patching the global fs module

This feature allows you to patch the global fs module with a virtual file system. In the code sample, a virtual file system is created with a single file '/foo.txt' containing the text 'bar'. The global fs module is then patched, so any subsequent fs operations in the process will interact with this virtual file system instead of the real one.

const {patchFs} = require('fs-monkey');
const {Volume} = require('memfs');
const vol = Volume.fromJSON({'/foo.txt': 'bar'});
patchFs(vol);

Creating a union file system

This feature allows you to create a union file system, which combines multiple file systems into a single coherent file system interface. In the code sample, a virtual file system is created and then combined with the real fs module using the union file system. This allows for fallback to the real file system for files not found in the virtual file system.

const {ufs} = require('fs-monkey');
const {Volume} = require('memfs');
const vol = Volume.fromJSON({'/foo.txt': 'bar'});
ufs.use(vol);
ufs.use(require('fs'));

Other packages similar to fs-monkey

Readme

Source

fs-monkey

Monkey-patches for filesystem related things.

  • Rewrite require function to load Node's modules from memory.
  • Or rewrite the whole fs filesystem module.

Install

npm install --save fs-monkey

Terms

An fs-like object is an object that implements methods of Node's filesystem API. It is denoted as vol:

let vol = {
    readFile: () => { /* ... */ },
    readFileSync: () => { /* ... */ },
    // etc...
}

Reference

  • patchFs - rewrites Node's filesystem module fs with fs-like object vol
  • patchRequire - rewrites require function, patches Node's module module to use a given fs-like object for module loading

License

Unlicense - public domain.

Keywords

FAQs

Last updated on 25 Sep 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