Permalink
Browse files

Update to version 0.1.6

  • Loading branch information...
1 parent 5212fae commit 91006eef766e68312548f9d9fef81a386cc64896 @nathanoehlman committed Dec 6, 2013
Showing with 14 additions and 13 deletions.
  1. +13 −12 lib/multipartupload.js
  2. +1 −1 package.json
@@ -41,28 +41,22 @@ function MultiPartUpload(opts, callback) {
this.maxUploadSize = opts.maxUploadSize || 1/0; // infinity default
this.currentUploadSize = 0;
this.aborted = false;
+ this.totalUploadSize = 0;
this.uploads.concurrency(opts.batchSize ||4); // 4 simultaneous uploads by default
// initialise the tmp directory based on opts (fallback to os.tmpDir())
this.tmpDir = !this.noDisk && (opts.tmpDir || os.tmpDir());
- if (opts.stream) {
- this._putStream(opts.stream, callback);
- } else {
- this._putFile(opts.file, callback);
- }
-
var mpu = this,
- written = 0,
- totalSize = 0;
+ written = 0;
- mpu.on('partProgress', function(data) {
+ mpu.on('partProgress', function(data) {
written += data.written;
mpu.emit('progress', {
written: written,
- total: totalSize,
- percent: written / totalSize * 100 | 0
+ total: mpu.totalUploadSize,
+ percent: written / mpu.totalUploadSize * 100 | 0
});
});
@@ -71,6 +65,12 @@ function MultiPartUpload(opts, callback) {
written = written - partWritten;
});
+ if (opts.stream) {
+ this._putStream(opts.stream, callback);
+ } else {
+ this._putFile(opts.file, callback);
+ }
+
}
util.inherits(MultiPartUpload, EventEmitter);
@@ -115,6 +115,7 @@ MultiPartUpload.prototype._putFile = function(file, callback) {
fs.lstat(file, function (err, stats) {
var remainingBytes = stats.size;
var offset = 0;
+ mpu.totalUploadSize = stats.size;
while (remainingBytes > mpu.partSize) {
var partId = parts.length + 1,
part = {
@@ -247,7 +248,7 @@ MultiPartUpload.prototype._handleStream = function(stream, callback) {
current.data = Buffer.concat([current.data, buffer]);
}
current.length += buffer.length;
- totalSize += buffer.length;
+ mpu.totalUploadSize += buffer.length;
// Check if we have a part
if (current.length >= mpu.partSize) {
View
@@ -1,6 +1,6 @@
{
"name": "knox-mpu",
- "version": "0.1.5",
+ "version": "0.1.6",
"description": "Provide multi part upload functionality to Amazon S3 using the knox library",
"keywords": ["aws", "amazon", "s3", "knox", "multi", "part", "upload"],
"main": "index.js",

0 comments on commit 91006ee

Please sign in to comment.