npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

jsfs

0.9.2 • Public • Published

JSFS

Build Status dependencies Status

JSFS is an advanced JavaScript file system interface and library, enabling you to quickly write applications which extensively make use of file systems.

In-memory file system

JSFS provides a nice and clean way to create file systems that are stored in memory with a nice and clean API which is almost identical to the NodeJS FS API.

import MemFS from "jsfs/memory"
 
const fs1 = new MemFS();
 
// we can use the NodeJS API while everything is stored in memory!
fs1.writeFileSync('bar.txt', 'some content for the file');
fs1.writeFileSync('foo.txt', 'yet another file with some other content');

Get rid of absolute paths

Want to provide a file system interface to your users but you don't want to expose internal directory structure? Use isolate() to do the work for you!

⚠️ This method is not guaranteed to be fully secure. If you want full isolation, use a virtualizer such as KVM or Xen.

import isolate from "jsfs/isolate"
 
import * as fs from "fs-extra"
 
const fs2 = isolate(fs, '/path/to/project')
 
// now all files will be relative to /path/to/project!
console.log(fs2.readFileSync('package.json').toString());

Use one or more file systems as a fallback

In some cases, you may need to write to a specific directory or file system while you data is coming from somewhere else. This is an ideal scenario for using merge().

import merge from "jsfs/merge"
 
// a more complex example ... the following statement will merge the two file
// systems together and provide one API to access them both 
const mergedfs = merge(fs1, fs2); 
 
// the following statement will try to read foo.txt from memory and then fall
back to /path/to/project/foo.txt 
mergedfs.readFileSync('foo.txt'); 

Features

  • Robust and future-proof TypeScript interface based on the NodeJS FileSystem API
  • Code splitting: only require what you really need
  • File system transforms: change the behaviour of an existing file system
  • Comes shipped with an in-memory file system

Current issues

  • NodeJS-style callbacks are supported but are not type-checked
  • Code still has to be extensively tested
  • Currently no support for watching files
  • API is still prone to changes. View the change log in order to remain up to date.

For more information see the list of open issues.

Documentation

License

Copyright 2017 Sam Vervaeck

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

install

npm i jsfs

Downloadsweekly downloads

0

version

0.9.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability