Coder Social home page Coder Social logo

relativistic-fs's Introduction

npm

relativistic-fs

Build Status Dependency Status

fs wrapper to force relative paths everywhere.

Useful when you want to restrict your Node application to a certain directory. Absolute paths won't work because of executable bits on all the top-level directories, for example:

fs.readFileSync('/root/apps/my-fancy-app/foo/bar')
// Needs execute bit on:
//   - /
//   - /root
//   - /root/apps
//   - /root/apps/my-fancy-app
//   - /root/apps/my-fancy-app/foo
// Needs read bit on:
//   - /root/apps/my-fancy-app/foo/bar

With relativistic-fs (assuming /root/apps/my-fancy-app is the working directory):

fs.readFileSync('/root/apps/my-fancy-app/foo/bar')  // translates to ./foo/bar
// Needs execute bit on:
//   - /root/apps/my-fancy-app
//   - /root/apps/my-fancy-app/foo
// Needs read bit on:
//   - /root/apps/my-fancy-app/foo/bar

See?

relativistic-fs can be applied on the top level of your application and all the modules (incl. dependencies) will just work even on the most stringent permission system (provided they don't genuinely need to access files they lack a permission to).

API

rfs = require('relativistic-fs')

relativistic-fs exposes all functions from the core fs module under the same name and interface:

rfs.readdir(__dirname, function (err, files) {
  // ...
});

rfs.install()

Replaces the core fs module with relativistic-fs so that any subsequent require('fs') calls return rfs. (Modifies require.cache.)

Returns rfs.

Wrapped functions

Functions that are wrapped to transform path arguments:

  • access(path[, mode], callback)
  • accessSync(path[, mode])
  • appendFile(file, data[, options], callback)
  • appendFileSync(file, data[, options])
  • chmod(path, mode, callback)
  • chmodSync(path, mode)
  • chown(path, uid, gid, callback)
  • chownSync(path, uid, gid)
  • createReadStream(path[, options])
  • createWriteStream(path[, options])
  • exists(path, callback)
  • existsSync(path)
  • lchmod(path, mode, callback)
  • lchmodSync(path, mode)
  • lchown(path, uid, gid, callback)
  • lchownSync(path, uid, gid)
  • link(srcpath, dstpath, callback)
  • linkSync(srcpath, dstpath)
  • lstat(path, callback)
  • lstatSync(path)
  • mkdir(path[, mode], callback)
  • mkdirSync(path[, mode])
  • open(path, flags[, mode], callback)
  • openSync(path, flags[, mode])
  • readFile(file[, options], callback)
  • readFileSync(file[, options])
  • readdir(path, callback)
  • readdirSync(path)
  • readlink(path, callback)
  • readlinkSync(path)
  • realpath(path[, cache], callback)
  • realpathSync(path[, cache])
  • rename(oldPath, newPath, callback)
  • renameSync(oldPath, newPath)
  • rmdir(path, callback)
  • rmdirSync(path)
  • stat(path, callback)
  • statSync(path)
  • symlink(target, path[, type], callback)
  • symlinkSync(target, path[, type])
  • truncate(path, len, callback)
  • truncateSync(path, len)
  • unlink(path, callback)
  • unlinkSync(path)
  • unwatchFile(filename[, listener])
  • utimes(path, atime, mtime, callback)
  • utimesSync(path, atime, mtime)
  • watch(filename[, options][, listener])
  • watchFile(filename[, options], listener)
  • writeFile(file, data[, options], callback)
  • writeFileSync(file, data[, options])

What's up with the name?

relative-fs was already taken.

Install

npm install relativistic-fs

License

MIT

relativistic-fs's People

Contributors

eush77 avatar

Watchers

James Cloos avatar  avatar

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.