Giter Site home page Giter Site logo

matrixai / js-virtualfs Goto Github PK

View Code? Open in Web Editor NEW
26.0 8.0 4.0 1.83 MB

In-memory filesystem written in JavaScript for Node.js and Browsers

License: Apache License 2.0

JavaScript 99.86% Nix 0.14%
filesystem filesystem-library in-memory-fs javascript nodejs

js-virtualfs's Introduction

VirtualFS

VirtualFS is a virtual posix-like filesystem that runs completely in memory. It is intended to work in browsers and in NodeJS. For browser usage, make use of a bundler like Webpack, Browserify or Rollup.

It includes:

  • Proper stat metadata with MAC time handling
  • Symlink support
  • Hardlink support
  • Virtual inodes
  • File descriptor support
  • Proper streams implementation
  • Character device support (/dev/null, /dev/full, /dev/tty...)
  • Current working directory support
  • Simulation of Unix file permissions
  • Umask is considered when creating new iNodes
  • Simulates POSIX filesystem errors
  • Emulates mmap with MAP_PRIVATE and MAP_SHARED
  • Usage of Flow types
  • Removal of all Windows path support
  • Practically complete compatibility with Node's FileSystem API

This package will be maintained as long as the Polykey project is maintained. All tests are passing in this fork.

Documentation

Documentation is located in the doc folder. You can also view the rendered HTML.

The VirtualFS API extends Node's fs API, while also leaving out functions that are not emulatable in-memory. For the functions that have the same name, you can just refer to Node's FS API: https://nodejs.org/api/fs.html. For the functions that don't have the name, refer to the generated API documentation that uses flow types. The source code is understandable so you can just read that as well.

To use VirtualFS as a global polyfill for fs, all you need to do is:

import vfs from 'virtualfs';
(typeof self === 'undefined' ? typeof global === 'undefined' ? this : global : self).fs = vfs;
// alternatively use the global package `import global from 'global'; global.fs = vfs;`

All subsequent uses of fs in the current module, subsequently imported modules, and any module that imports the current module will also use the same fs. The above monkeypatch works in Node, Browsers and Web Workers. However this will also make /dev/tty not work because it uses Node's real fs. Instead you should rely on a per-module override. Unless of course you're not using /dev/tty in Node.

In order to only override on a per-module basis you'll need to use the rewire package or the https://github.com/speedskater/babel-plugin-rewire babel plugin.

When using this in a CommonJS environment, you can gain access to the default fs replacement by using var fs = require('virtualfs').default;.

Development

To run flow type checks:

flow status
flow stop

To build this package for release:

npm run build

It will run tests, generate documentation and output multiple targets. One for browsers and one for nodejs. See rollup.config.js to see the target specification.

If your bundler is aware of the module field in package.json, you'll get the ES6 module directly.

Once you've updated the package run this:

npm version <update_type>
npm publish

The browser target makes use of these polyfills:

  • buffer - Used everywhere.
  • events - Used by streams dependency.
  • path - Used for join.
  • process - Used for nextTick and stdin and stdout streams.
  • stream - Used for filesystem streaming

They are currently supplied through Rollup plugins.

Todo

  • Investigate mounting implementation

js-virtualfs's People

Contributors

cmcdragonkai avatar emolchanov avatar eventualbuddha avatar gajus avatar izaakschroeder avatar kpdecker avatar mjackson avatar montogeek avatar sokra avatar spacek33z avatar termina1 avatar thelarkinn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-virtualfs's Issues

_

_

VFS not able to recursively delete directories

Here you can see VFS throws an Error when the provided path is a directory:

throw new VirtualFSError(errno.ENOTDIR, path, null, 'rmdir');

Its not good to go chasing the proverbial rabbit and keep updating to match the fs interface but this seems like a core functionality that VFS should have.

This issue is related to js-encryptedfs as in we want to be able to mirror what we can do on the lowerDir when we delete a directory.

Pending stat data integration

Add stat data integration (optional to the underlying data model). It is optional so for things that don't need the extra stat integration they don't need it, and the stat part will be left undefined.

Upstream Problem with `process` polyfill

The process polyfill hasn't added the platform property which makes not only your own code fail but also other libraries fail that expect there to be a platform property.

defunctzombie/node-process#55

Then test with:

<html>
  <head>
    <meta charset="UTF-8">
    <title>test</title>
    <script type="text/javascript" src="./dist/index.browser.umd.js"></script>
  </head>
  <body>
    <p>test</p>
  </body>
</html>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.