0.1.0 • Published 11 years ago
s3rw v0.1.0
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 bepublic-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>"
}
0.1.0
11 years ago