koop-localfs

A local filesystem plugin for koop

Usage no npm install needed!

<script type="module">
  import koopLocalfs from 'https://cdn.skypack.dev/koop-localfs';
</script>

README

Koop Local FS

Greenkeeper badge A filesystem plugin for koop that supports setting a root directory for all actions

npm travis

Project goal

In order to allow different koop modules to write to local disk without specifying a machine specific absolute path, this module resolves all relative paths to the same base directory. So you can callkoop.fs.createReadStream('foo.txt') and always know that you can open foo without changing the working directory.

Usage

In default.json

{
  "filesystem": {
    "local": {
      "rootDir": "/var/koop/files"
    }
  }
}

In server.js

const config = require('config')
const koop = require('koop')(config)
const LocalFs = require('koop-localfs')

koop.register(LocalFs)

Supported functions

  • stat - Get information about a file
  • createReadStream: create a readable stream from a file on disk
  • createWriteStream: create a writeable stream you can pipe to
  • writeFile: write a file to disk
  • readFile: read a file from disk
  • unlink: delete a file
  • mkdir: make a directory
  • rmdir: remove an empty directory
  • rmdirp: recursively remove a directory and its contents
  • realpathSync: resolve the absolute path when given a relative path