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
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
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
}
Write a new value.
Read a value out
Delete a value
Delete multiple values. Objects should look like this:
{
key: `value/key`, // required
version: `version` // optional
}
Create a readable stream to a key.
Create a writeable stream to a key. Options include
{
length: sizeOfStream, // required
}
Rename a folder/file
Check if a key exists.
Return stat info about a key. The returned object looks like this:
{
size: sizeOfValue,
modified: lastModifiedDate
}
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.
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
}
This project was kindly sponsored by nearForm.
MIT