Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Configurable temporary file location #3

Merged
merged 3 commits into from

2 participants

@DamonOehlman

Hey Nathan,

Just made a tweak to the multipart uploader so it let's you configure the temporary folder location (falls back to os.tmpDir() if none specified).

Additionally, just a few syntax tweaks that jshint was nagging me about.

Also, I reckon this module deserves at least a 0.1.x status :)

Have a good weekend!

Cheers,
Damon.

@DamonOehlman

Actually, Nathan I'm just doing one more thing now and that's around updating package versions to the current latest required. Additionally, I think I can move knox from dependencies to devDependencies so doing that now too...

@nathanoehlman nathanoehlman merged commit 6ec4355 into nathanoehlman:master
@nathanoehlman

Hey Damon,

Nice thinking about the configurable location - I've merged all the changes in and bumped the version to 0.1.0.

Cheers,
Nathan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 14 deletions.
  1. +3 −0  .jshintrc
  2. +13 −10 lib/multipartupload.js
  3. +5 −4 package.json
View
3  .jshintrc
@@ -0,0 +1,3 @@
+{
+ "indent": 4
+}
View
23 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-' + (mpu.uploadId || Date.now()) + '-' + partId)),
+ partFileName = path.resolve(path.join(mpu.tmpDir, 'mpu-' + (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,6 +250,6 @@ MultiPartUpload.prototype._completeUploads = function(callback) {
req.write('<CompleteMultipartUpload>' + parts + '</CompleteMultipartUpload>');
req.end();
});
-}
+};
module.exports = MultiPartUpload;
View
9 package.json
@@ -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"
}
}
Something went wrong with that request. Please try again.