knox-mpu-alt
Advanced tools
Comparing version 0.1.8 to 0.1.9
@@ -6,2 +6,3 @@ var _ = require('lodash'), | ||
path = require('path'), | ||
fsx = require('fs-extra'), | ||
os = require('os'), | ||
@@ -15,16 +16,26 @@ util = require('util'), | ||
function MultiPartUpload(opts, callback) { | ||
var e; | ||
if (!opts.client || !opts.objectName) { | ||
throw new Error('MultiPart upload must be created from a client and provide an object name'); | ||
e = new Error('MultiPart upload must be created from a client and provide an object name'); | ||
if (callback) return callback(e); | ||
throw e; | ||
} | ||
if (!opts.stream && !opts.file) { | ||
throw new Error('MultiPart upload must be passed either a stream or file parameter'); | ||
e = new Error('MultiPart upload must be passed either a stream or file parameter'); | ||
if (callback) return callback(e); | ||
throw e; | ||
} | ||
if (opts.stream && opts.file) { | ||
throw new Error('You cannot provide both a stream and a file to upload'); | ||
e = new Error('You cannot provide both a stream and a file to upload'); | ||
if (callback) return callback(e); | ||
throw e; | ||
} | ||
if (opts.noDisk && opts.partSize && opts.partSize > 10485760) { | ||
throw new Error('Keep in-memory part sizes 10MB or less'); | ||
e = new Error('Keep in-memory part sizes 10MB or less'); | ||
if (callback) return callback(e); | ||
throw e; | ||
} | ||
@@ -57,30 +68,41 @@ | ||
// If we're buffering to disk, double the "totalUploadSize" we expect since | ||
// every byte has to be uploaded twice (once to disk, once to S3) | ||
if (!this.noDisk) {this.totalUploadSize *= 2;} | ||
var mpu = this; | ||
var mpu = this, | ||
written = 0; | ||
// ensure the tmpdir exists | ||
// (as well as the entire path leading to it) | ||
(function ensureTmpDirExists(afterwards){ | ||
if (!mpu.tmpDir) return afterwards(); | ||
fsx.ensureDir(mpu.tmpDir, afterwards); | ||
})(function(err) { | ||
if (err) return callback(err); | ||
mpu.on('partProgress', function(data) { | ||
written += data.written; | ||
var percent = written / mpu.totalUploadSize * 100 | 0; | ||
mpu.percentUploaded = percent; | ||
mpu.emit('progress', { | ||
written: written, | ||
total: mpu.totalUploadSize, | ||
percent: mpu.percentUploaded | ||
}); | ||
}); | ||
// If we're buffering to disk, double the "totalUploadSize" we expect since | ||
// every byte has to be uploaded twice (once to disk, once to S3) | ||
if (!mpu.noDisk) {mpu.totalUploadSize *= 2;} | ||
// Recalculate progress as previously written data needs to be rewritten | ||
mpu.on('failed', function(part, partWritten) { | ||
written = written - partWritten; | ||
var written = 0; | ||
mpu.on('partProgress', function(data) { | ||
written += data.written; | ||
var percent = written / mpu.totalUploadSize * 100 | 0; | ||
mpu.percentUploaded = percent; | ||
mpu.emit('progress', { | ||
written: written, | ||
total: mpu.totalUploadSize, | ||
percent: mpu.percentUploaded | ||
}); | ||
}); | ||
// Recalculate progress as previously written data needs to be rewritten | ||
mpu.on('failed', function(part, partWritten) { | ||
written = written - partWritten; | ||
}); | ||
if (opts.stream) { | ||
mpu._putStream(opts.stream, callback); | ||
} else { | ||
mpu._putFile(opts.file, callback); | ||
} | ||
}); | ||
if (opts.stream) { | ||
this._putStream(opts.stream, callback); | ||
} else { | ||
this._putFile(opts.file, callback); | ||
} | ||
@@ -186,3 +208,3 @@ } | ||
if (err || !uploadId) return callback('Unable to initiate stream upload [' + err || 'No upload ID' + ']'); | ||
}); | ||
}); | ||
} | ||
@@ -298,3 +320,3 @@ // Start handling the stream straight away | ||
return callback(err); | ||
}); | ||
}); | ||
}; | ||
@@ -331,3 +353,3 @@ | ||
return MultiPartUpload.prototype._uploadPart.call(mpu, part, callback); | ||
} | ||
} | ||
// Otherwise bail out | ||
@@ -375,3 +397,3 @@ else { | ||
else { | ||
// Make sure the callback is only called once | ||
// Make sure the callback is only called once | ||
part.alreadyCB = true; | ||
@@ -378,0 +400,0 @@ return callback(result); |
{ | ||
"name": "knox-mpu-alt", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "Provide multi part upload functionality to Amazon S3 using the knox library. Forked from knox-mpu.", | ||
@@ -27,5 +27,6 @@ "keywords": [ | ||
"dependencies": { | ||
"async": "^0.9.0", | ||
"lodash": "1.0.x", | ||
"xml2js": "0.2.x" | ||
"async": "~0.9.0", | ||
"lodash": "~2.4.0", | ||
"xml2js": "~0.2.0", | ||
"fs-extra": "~0.10.0" | ||
}, | ||
@@ -32,0 +33,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34486
9
572
4
3
1
+ Addedfs-extra@~0.10.0
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs-extra@0.10.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedjsonfile@1.2.0(transitive)
+ Addedlodash@2.4.2(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedncp@0.5.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedlodash@1.0.2(transitive)
Updatedasync@~0.9.0
Updatedlodash@~2.4.0
Updatedxml2js@~0.2.0