Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

knox-mpu-alt

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knox-mpu-alt - npm Package Compare versions

Comparing version 0.1.8 to 0.1.9

.editorconfig

84

lib/multipartupload.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc