Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

koop-s3fs

koopjs44Apache-2.01.2.2

An AWS S3-backed filesystem plugin for Koop

koop, s3, aws, fs, files

readme

koop-s3fs

Build Status

Koop integration with Amazon S3

Install

koop-s3fs should be installed as a dependency in a Node.js project like so:

npm install koop-s3fs --save

Config

koop-s3fs requires a json config file like so:

{
  "filesystem": {
    "s3": {
      "bucket": $S3_BUCKET,
      "endpoint" $S3-ENDPOINT //optional https://forums.aws.amazon.com/ann.jspa?annID=3112
    }
  }
}

Additionally you will need to supply your:

AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY

or configure the AWS CLI with keys.

Methods

const Filesystem = require('koop-s3fs')
const s3fs = new Filesystem()
const fs = require('fs')

/**
 * createWriteStream writes to AWS S3 as a Highland stream
 *
 * @param {string} name - filename
 * @param {object} options - optional metadata to attach to file
 * @returns {stream} stream
 */

const stream = fs.createReadStream('path/to/file')
  .pipe(s3fs.createWriteStream('filename'))


/**
 * createReadStream reads file from AWS s3 as highland stream
 *
 * @param {string} file - filename
 * @returns {stream}
 */

s3fs.createReadStream('filename').toArray(arr => {
  const txt = arr.toString()
  console.log(txt)
})


/**
 * stat accesses file metadata
 *
 * @param {string} file - filename
 * @param {function} callback
 * @returns {promise} returns resolved promise
 */

s3fs.stat('filename', (err, data) => {
  console.log(data)
  /*  Stats {
      getEntry: [Function],
      dev: 0,
      mode: 0,
      nlink: 0,
      uid: 0,
      gid: 0,
      rdev: 0,
      blksize: undefined,
      ino: 0,
      size: 37,
      blocks: undefined,
      atime: Wed Apr 13 2016 13:15:14 GMT-0400 (EDT),
      mtime: Wed Apr 13 2016 13:15:14 GMT-0400 (EDT),
      ctime: Wed Apr 13 2016 13:15:14 GMT-0400 (EDT),
      birthtime: Invalid Date,
      acceptRanges: 'bytes',
      ETag: '"b3b285a1749957f3e3a627a8e92b65bc"',
      ContentType: 'application/octet-stream',
      Metadata: { test: 'this is a test' } }
  */
})

changelog

Change Log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

1.2.2 - 2016-10-17

Fixed

  • prevent nil from being written twice on write streams

1.2.1 - 2016-10-14

Changed

1.2.0 - 2016-05-06

Added

  • Option to specify content-type on createWriteStream

1.1.3 - 2016-04-28

Changed

  • createReadStream will time out after 30 seconds
  • createReadStream will emit an error if the content is empty

1.1.2 - 2016-04-27

Added

  • Option to disable automatic gunzipping of createReadStream content with {gunzip: false}

1.1.1 - 2016-04-27

Changed

  • Stat object includes content encoding

1.1.0 - 2016-04-16

Added

  • realPathSync returns url location when given relative path
  • Set Content-Encoding header on saved files

1.0.2 - 2016-04-13

Changed

  • Type, plugin_name, dependencies, version accessible from class object