Permalink
Browse files

Merge pull requests from DamonOehlman and amdstorm, bump version

  • Loading branch information...
2 parents a7c1cae + 6ec4355 commit 1214e78c7deb67be9a9ffb80a1df7cffa573a8e0 @nathanoehlman committed Mar 7, 2013
Showing with 23 additions and 16 deletions.
  1. +3 −0 .jshintrc
  2. +14 −11 lib/multipartupload.js
  3. +6 −5 package.json
View
3 .jshintrc
@@ -0,0 +1,3 @@
+{
+ "indent": 4
+}
View
25 lib/multipartupload.js
@@ -29,6 +29,9 @@ function MultiPartUpload(opts, callback) {
this.partSize = opts.partSize || 5242880; // 5MB default
this.uploadId = null;
this.uploads = new Batch();
+
+ // initialise the tmp directory based on opts (fallback to os.tmpDir())
+ this.tmpDir = opts.tmpDir || os.tmpDir();
if (opts.stream) {
this._putStream(opts.stream, callback);
@@ -59,7 +62,7 @@ MultiPartUpload.prototype._initiate = function(callback) {
});
req.end();
-}
+};
/**
* Streams a file to S3 using a multipart form upload
@@ -79,7 +82,7 @@ MultiPartUpload.prototype._putFile = function(file, callback) {
var stream = fs.createReadStream(file);
mpu._putStream(stream, callback);
});
-}
+};
/**
* Streams a stream to S3 using a multipart form upload.
@@ -101,7 +104,7 @@ MultiPartUpload.prototype._putStream = function(stream, callback) {
}
// Start handling the stream straight away
mpu._handleStream(stream, callback);
-}
+};
/**
Handles an incoming stream, divides it into parts, and uploads it to S3
@@ -115,7 +118,7 @@ MultiPartUpload.prototype._handleStream = function(stream, callback) {
// Create a new part
function newPart() {
var partId = parts.length + 1,
- partFileName = path.resolve(path.join(os.tmpDir(), 'mpu-' + this.objectName + '-' + random_seed() + '-' + (mpu.uploadId || Date.now()) + '-' + partId)),
+ partFileName = path.resolve(path.join(mpu.tmpDir, 'mpu-' + this.objectName + '-' + random_seed() + '-' + (mpu.uploadId || Date.now()) + '-' + partId)),
partFile = fs.createWriteStream(partFileName),
part = {
id: partId,
@@ -129,7 +132,7 @@ MultiPartUpload.prototype._handleStream = function(stream, callback) {
}
function partReady(part) {
- if (!part) return
+ if (!part) return;
// Ensure the stream is closed
if (part.stream.writable) {
@@ -169,7 +172,7 @@ MultiPartUpload.prototype._handleStream = function(stream, callback) {
// Clean up
return callback(err);
});
-}
+};
/**
Uploads a part, or if we are not ready yet, waits for the upload to be initiated
@@ -179,7 +182,7 @@ MultiPartUpload.prototype._uploadPart = function(part, callback) {
// If we haven't started the upload yet, wait for the initialization
if (!this.uploadId) {
- return this.on('initiated', this._uploadPart.bind(this, part, callback));
+ return this.on('initiated', this._uploadPart.bind(this, part, callback));
}
var url = this.objectName + '?partNumber=' + part.id + '&uploadId=' + this.uploadId,
@@ -193,7 +196,7 @@ MultiPartUpload.prototype._uploadPart = function(part, callback) {
if (res.statusCode != 200) return callback({part: part.id, message: 'Upload failed'});
// Grab the etag and return it
- var etag = res.headers['etag'],
+ var etag = res.headers.etag,
result = {part: part.id, etag: etag, size: part.length};
mpu.emit('uploaded', result);
@@ -213,7 +216,7 @@ MultiPartUpload.prototype._uploadPart = function(part, callback) {
partStream.pipe(req);
mpu.emit('uploading', part.id);
-}
+};
/**
Indicates that all uploads have been started and that we should wait for completion
@@ -247,10 +250,10 @@ MultiPartUpload.prototype._completeUploads = function(callback) {
req.write('<CompleteMultipartUpload>' + parts + '</CompleteMultipartUpload>');
req.end();
});
-}
+};
module.exports = MultiPartUpload;
function random_seed(){
return 'xxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);});
-}
+}
View
11 package.json
@@ -1,6 +1,6 @@
{
"name": "knox-mpu",
- "version": "0.0.4",
+ "version": "0.1.0",
"description": "Provide multi part upload functionality to Amazon S3 using the knox library",
"keywords": ["aws", "amazon", "s3", "knox", "multi", "part", "upload"],
"main": "index.js",
@@ -14,12 +14,13 @@
"author": "Nathan Oehlman",
"license": "BSD",
"dependencies": {
- "batch": "~0.2.0",
- "knox": "~0.4.0",
- "xml2js": "~0.2.0",
- "lodash": "~0.9.0"
+ "batch": "0.2.x",
+ "xml2js": "0.2.x",
+ "lodash": "1.0.x"
},
"devDependencies": {
+ "knox": "0.5.x",
+ "mocha": "1.8.x",
"mockstream": "0.0.0"
}
}

0 comments on commit 1214e78

Please sign in to comment.