Giter Site home page Giter Site logo

s3-storage's Introduction

s3-storage

Small module wrapper for the AWS sdk that allows you to easily use s3.

Supports the local file system as well with the same set of operations so you can easily develop without having internet access

npm install s3-storage

build status

Usage

var s3 = require('s3-storage')('my-bucket', {
  secretAccessKey: '...',
  accessKeyId: '...'
})

s3.put('hello', 'world', function () {
  s3.get('hello', console.log)
})

Or if you want use the file system locally instead

var s3 = require('s3-storage')('my-bucket', {
  type: 'fs' // will store the data in ./my-bucket
})

// s3 has the same api

API

var s3 = s3storage(bucket, [options])

Make a new storage instance. Options include:

{
  type: 's3' | 'fs' // defaults to s3
  secretAccessKey: '...'
  accessKeyId: '...', // both forwarded to the AWS sdk
  region: 'us-west-2', // the default region
  // Prefix all operations. eg `test` to prefix all under `test/`
  // note that '' results in the empty prefix, which means all your objects
  // will go in the folder `/`
  prefix: null
}

s3.put(key, value, [metadata], [callback])

Write a new value.

s3.get(key, callback)

Read a value out

s3.del(key, [callback])

Delete a value

s3.delBatch(objects, [callback])

Delete multiple values. Objects should look like this:

{
  key: `value/key`, // required
  version: `version` // optional
}

s3.createReadStream(key, options)

Create a readable stream to a key.

s3.createWriteStream(key, options)

Create a writeable stream to a key. Options include

{
  length: sizeOfStream, // required
}

s3.rename(src, dest, [callback])

Rename a folder/file

s3.exists(key, callback)

Check if a key exists.

s3.stat(key, callback)

Return stat info about a key. The returned object looks like this:

{
  size: sizeOfValue,
  modified: lastModifiedDate
}

s3.versions(key, callback)

Get a list of versions of a specific key. You can pass the version to stat, exists, get, createReadStream and del to interact with a specific one.

var stream = s3.list([options])

Create a list stream. Each data emitted looks like this

{
  key: 'value/key', // the value key
  size: 24, // how many bytes
  modified: Date() // when was it modified last?
}

Options include:

{
  prefix: 'foo', // only list keys under foo
  marker: 'foo/bar/baz', // only list keys after foo/bar/baz
  limit: 14 // only return this many
}

Acknowledgements

This project was kindly sponsored by nearForm.

License

MIT

s3-storage's People

Contributors

emilbayes avatar goto-bus-stop avatar luddd3 avatar mafintosh 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  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  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

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.