Skip to content

Commit

Permalink
add copy method
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Mar 2, 2012
1 parent 5ffa8b8 commit d6ead85
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
10 changes: 9 additions & 1 deletion README.md
Expand Up @@ -27,7 +27,15 @@ s3.get('/some/path', {'x-amz-acl': 'private'}, function(err, body) {

## s3.get(path, [headers], callback)

## s3.put(path, [headers], data, callback)
## s3.put(path, headers, data, callback)
Requires ```Content-Type``` and ```Content-Length``` headers

## s3.delete(path, [headers], callback)

## s3.copy(dst_path, src_path, src_bucket, headers, callback)

* dst_path - the destination filename
* src_path - the source filename
* src_bucket - the source bucket. The dst_bucket is the bucket passed to the constructor.

Requires ```Content-Type``` and ```Content-Length``` headers
15 changes: 15 additions & 0 deletions index.js
Expand Up @@ -96,3 +96,18 @@ S3.prototype.delete = function(path, headers, callback) {
callback();
}).end();
};

S3.prototype.copy = function(dst_path, src_path, src_bucket, headers, callback) {
if (typeof headers === 'function') {
callback = headers;
headers = {};
}
var src_header = '/'+src_bucket;
if (src_path.indexOf('/') === 0) {
src_header += src_path;
} else {
src_header += '/' + src_path;
}
headers['x-amz-copy-source'] = src_header;
this.put(dst_path, headers, '', callback);
};
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"author": "Andrew J. Stone <andrew.j.stone.1@gmail.com>",
"name": "s3asy",
"description": "Simple S3 integration with a cache backed by Redis",
"version": "0.1.2",
"version": "0.2.0",
"repository": {
"type": "git",
"url": "git://github.com/andrewjstone/s3asy.git"
Expand Down

0 comments on commit d6ead85

Please sign in to comment.