s3rw

0.1.0 • Public • Published

node-s3rw

A node-task compliant read-write interface for Amazon S3.

API

read(path, options)

Read a file from Amazon S3 and return a promise which resolves to a node-task compliant record.

The options object supports these keys:

  • client A aws2js S3 client (required).
  • bucket S3 source bucket (required).
  • encoding The encoding of the file to be read.
var s3rw = require('s3rw')
var options = {
  client: require('aws2js').load('s3', '<key>', '<secret>'),
  bucket: '<bucket>'
};
s3rw.read('test.txt', options).then(function (self) {
  console.log(self.toString()) // 'file contents'
});

write(record, options)

Save a node-task record to Amazon S3.

The options object supports these keys:

  • client A aws2js S3 client (required).
  • bucket The destination bucket (required).
  • acl A valid Canned ACL. Defaults to 'private'. Can also be public-read, public-write, public-read-write, authenticated-read.
  • headers Set headers for uploaded file (far-future, etc).
var Record = require('record');
var s3rw = require('s3rw');
var options = {
  client: require('aws2js').load('s3', '<key>', '<secret>'),
  bucket: '<bucket>',
  acl: 'private', // 'public-read' | 'public-read-write' | 'authenticated-read'
  headers: {
    "Cache-Control": "max-age=315360000"
  }
};
 
var file = new Record('test.txt', 'utf8', 'test file');
s3rw.save(file, opts).then(function(self) {
  console.log(self); // file
});

Running Tests

To run the test suite you must first have an S3 account. Then create a file named ./test/s3.json, which contains your credentials and test bucket in this format:

{
  "key": "<api-key-here>",
  "secret": "<secret-here>",
  "bucket": "<your-bucket-name>"
}

Readme

Keywords

none

Package Sidebar

Install

npm i s3rw

Weekly Downloads

0

Version

0.1.0

License

none

Last publish

Collaborators

  • tkellen