diff --git a/lib/index.js b/lib/index.js index 526f5f1..d122cb1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -22,7 +22,7 @@ var MIN_MULTIPART_SIZE = 5 * 1024 * 1024; var TO_UNIX_RE = new RegExp(quotemeta(path.sep), 'g'); -exports.createClient = function(options) { +exports.createClient = function (options) { return new Client(options); }; @@ -64,7 +64,7 @@ function Client(options) { } } -Client.prototype.deleteObjects = function(s3Params) { +Client.prototype.deleteObjects = function (s3Params) { var self = this; var ee = new EventEmitter(); @@ -81,7 +81,7 @@ Client.prototype.deleteObjects = function(s3Params) { ee.progressTotal = params.Delete.Objects.length; slices.forEach(uploadSlice); - pend.wait(function(err) { + pend.wait(function (err) { if (err) { ee.emit('error', err); return; @@ -91,8 +91,8 @@ Client.prototype.deleteObjects = function(s3Params) { return ee; function uploadSlice(slice) { - pend.go(function(cb) { - doWithRetry(tryDeletingObjects, self.s3RetryCount, self.s3RetryDelay, function(err, data) { + pend.go(function (cb) { + doWithRetry(tryDeletingObjects, self.s3RetryCount, self.s3RetryDelay, function (err, data) { if (err) { cb(err); } else { @@ -105,9 +105,9 @@ Client.prototype.deleteObjects = function(s3Params) { }); function tryDeletingObjects(cb) { - self.s3Pend.go(function(pendCb) { + self.s3Pend.go(function (pendCb) { params.Delete.Objects = slice; - self.s3.deleteObjects(params, function(err, data) { + self.s3.deleteObjects(params, function (err, data) { pendCb(); cb(err, data); }); @@ -116,17 +116,17 @@ Client.prototype.deleteObjects = function(s3Params) { } }; -Client.prototype.uploadFile = function(params) { +Client.prototype.uploadFile = function (params) { var self = this; var uploader = new EventEmitter(); uploader.progressMd5Amount = 0; uploader.progressAmount = 0; uploader.progressTotal = 0; uploader.abort = handleAbort; - uploader.getPublicUrl = function() { + uploader.getPublicUrl = function () { return getPublicUrl(s3Params.Bucket, s3Params.Key, self.s3.config.region, self.s3.config.endpoint); } - uploader.getPublicUrlHttp = function() { + uploader.getPublicUrlHttp = function () { return getPublicUrlHttp(s3Params.Bucket, s3Params.Key, self.s3.config.endpoint); } @@ -160,11 +160,11 @@ Client.prototype.uploadFile = function(params) { } function openFile() { - fs.open(localFile, 'r', function(err, fd) { + fs.open(localFile, 'r', function (err, fd) { if (err) return handleError(err); - localFileSlicer = fd_slicer.createFromFd(fd, {autoClose: true}); + localFileSlicer = fd_slicer.createFromFd(fd, { autoClose: true }); localFileSlicer.on('error', handleError); - localFileSlicer.on('close', function() { + localFileSlicer.on('close', function () { uploader.emit('fileClosed'); }); @@ -174,7 +174,7 @@ Client.prototype.uploadFile = function(params) { uploader.emit('fileOpened', localFileSlicer); - fs.fstat(fd, function(err, stat) { + fs.fstat(fd, function (err, stat) { if (err) return handleError(err); localFileStat = stat; uploader.progressTotal = stat.size; @@ -213,7 +213,7 @@ Client.prototype.uploadFile = function(params) { } function startMultipartUpload(multipartUploadSize) { - doWithRetry(tryCreateMultipartUpload, self.s3RetryCount, self.s3RetryDelay, function(err, data) { + doWithRetry(tryCreateMultipartUpload, self.s3RetryCount, self.s3RetryDelay, function (err, data) { if (fatalError) return; if (err) return handleError(err); uploader.emit('data', data); @@ -246,7 +246,7 @@ Client.prototype.uploadFile = function(params) { parts.push(part); pend.go(makeUploadPartFn(start, end, part, uploadId)); } - pend.wait(function(err) { + pend.wait(function (err) { if (fatalError) return; if (err) return handleError(err); completeMultipartUpload(); @@ -254,8 +254,8 @@ Client.prototype.uploadFile = function(params) { } function makeUploadPartFn(start, end, part, uploadId) { - return function(cb) { - doWithRetry(tryUploadPart, self.s3RetryCount, self.s3RetryDelay, function(err, data) { + return function (cb) { + doWithRetry(tryUploadPart, self.s3RetryCount, self.s3RetryDelay, function (err, data) { if (fatalError) return; if (err) return handleError(err); uploader.emit('part', data); @@ -265,14 +265,14 @@ Client.prototype.uploadFile = function(params) { function tryUploadPart(cb) { if (fatalError) return; - self.s3Pend.go(function(pendCb) { + self.s3Pend.go(function (pendCb) { if (fatalError) { pendCb(); return; } - var inStream = localFileSlicer.createReadStream({start: start, end: end}); + var inStream = localFileSlicer.createReadStream({ start: start, end: end }); var errorOccurred = false; - inStream.on('error', function(err) { + inStream.on('error', function (err) { if (fatalError || errorOccurred) return; handleError(err); }); @@ -280,12 +280,12 @@ Client.prototype.uploadFile = function(params) { s3Params.PartNumber = part.PartNumber; s3Params.UploadId = uploadId; - var multipartETag = new MultipartETag({size: s3Params.ContentLength, count: 1}); + var multipartETag = new MultipartETag({ size: s3Params.ContentLength, count: 1 }); var prevBytes = 0; var overallDelta = 0; var pend = new Pend(); var haveETag = pend.hold(); - multipartETag.on('progress', function() { + multipartETag.on('progress', function () { if (fatalError || errorOccurred) return; var delta = multipartETag.bytes - prevBytes; prevBytes = multipartETag.bytes; @@ -293,7 +293,7 @@ Client.prototype.uploadFile = function(params) { overallDelta += delta; uploader.emit('progress'); }); - multipartETag.on('end', function() { + multipartETag.on('end', function () { if (fatalError || errorOccurred) return; var delta = multipartETag.bytes - prevBytes; uploader.progressAmount += delta; @@ -304,7 +304,7 @@ Client.prototype.uploadFile = function(params) { inStream.pipe(multipartETag); s3Params.Body = multipartETag; - self.s3.uploadPart(extend({}, s3Params), function(err, data) { + self.s3.uploadPart(extend({}, s3Params), function (err, data) { pendCb(); if (fatalError || errorOccurred) return; if (err) { @@ -313,7 +313,7 @@ Client.prototype.uploadFile = function(params) { cb(err); return; } - pend.wait(function() { + pend.wait(function () { if (fatalError) return; if (!compareMultipartETag(data.ETag, multipartETag)) { errorOccurred = true; @@ -332,7 +332,7 @@ Client.prototype.uploadFile = function(params) { function completeMultipartUpload() { localFileSlicer.unref(); localFileSlicer = null; - doWithRetry(tryCompleteMultipartUpload, self.s3RetryCount, self.s3RetryDelay, function(err, data) { + doWithRetry(tryCompleteMultipartUpload, self.s3RetryCount, self.s3RetryDelay, function (err, data) { if (fatalError) return; if (err) return handleError(err); uploader.emit('end', data); @@ -341,7 +341,7 @@ Client.prototype.uploadFile = function(params) { function tryCompleteMultipartUpload(cb) { if (fatalError) return; - self.s3Pend.go(function(pendCb) { + self.s3Pend.go(function (pendCb) { if (fatalError) { pendCb(); return; @@ -354,7 +354,7 @@ Client.prototype.uploadFile = function(params) { Parts: parts, }, }; - self.s3.completeMultipartUpload(s3Params, function(err, data) { + self.s3.completeMultipartUpload(s3Params, function (err, data) { pendCb(); if (fatalError) return; cb(err, data); @@ -364,9 +364,9 @@ Client.prototype.uploadFile = function(params) { function tryCreateMultipartUpload(cb) { if (fatalError) return; - self.s3Pend.go(function(pendCb) { + self.s3Pend.go(function (pendCb) { if (fatalError) return pendCb(); - self.s3.createMultipartUpload(s3Params, function(err, data) { + self.s3.createMultipartUpload(s3Params, function (err, data) { pendCb(); if (fatalError) return; cb(err, data); @@ -375,14 +375,14 @@ Client.prototype.uploadFile = function(params) { } function tryPuttingObject(cb) { - self.s3Pend.go(function(pendCb) { + self.s3Pend.go(function (pendCb) { if (fatalError) return pendCb(); var inStream = localFileSlicer.createReadStream(); inStream.on('error', handleError); var pend = new Pend(); - var multipartETag = new MultipartETag({size: localFileStat.size, count: 1}); - pend.go(function(cb) { - multipartETag.on('end', function() { + var multipartETag = new MultipartETag({ size: localFileStat.size, count: 1 }); + pend.go(function (cb) { + multipartETag.on('end', function () { if (fatalError) return; uploader.progressAmount = multipartETag.bytes; uploader.progressTotal = multipartETag.bytes; @@ -392,7 +392,7 @@ Client.prototype.uploadFile = function(params) { cb(); }); }); - multipartETag.on('progress', function() { + multipartETag.on('progress', function () { if (fatalError) return; uploader.progressAmount = multipartETag.bytes; uploader.emit('progress'); @@ -402,14 +402,14 @@ Client.prototype.uploadFile = function(params) { inStream.pipe(multipartETag); s3Params.Body = multipartETag; - self.s3.putObject(s3Params, function(err, data) { + self.s3.putObject(s3Params, function (err, data) { pendCb(); if (fatalError) return; if (err) { cb(err); return; } - pend.wait(function() { + pend.wait(function () { if (fatalError) return; if (!compareMultipartETag(data.ETag, localFileStat.multipartETag)) { cb(new Error("ETag does not match MD5 checksum")); @@ -422,7 +422,7 @@ Client.prototype.uploadFile = function(params) { } }; -Client.prototype.downloadFile = function(params) { +Client.prototype.downloadFile = function (params) { var self = this; var downloader = new EventEmitter(); var localFile = params.localFile; @@ -430,13 +430,13 @@ Client.prototype.downloadFile = function(params) { var dirPath = path.dirname(localFile); downloader.progressAmount = 0; - mkdirp(dirPath, function(err) { + mkdirp(dirPath, function (err) { if (err) { downloader.emit('error', err); return; } - doWithRetry(doDownloadWithPend, self.s3RetryCount, self.s3RetryDelay, function(err) { + doWithRetry(doDownloadWithPend, self.s3RetryCount, self.s3RetryDelay, function (err) { if (err) { downloader.emit('error', err); return; @@ -448,8 +448,8 @@ Client.prototype.downloadFile = function(params) { return downloader; function doDownloadWithPend(cb) { - self.s3Pend.go(function(pendCb) { - doTheDownload(function(err) { + self.s3Pend.go(function (pendCb) { + doTheDownload(function (err) { pendCb(); cb(err); }); @@ -461,7 +461,7 @@ Client.prototype.downloadFile = function(params) { var errorOccurred = false; var hashCheckPend = new Pend(); - request.on('httpHeaders', function(statusCode, headers, resp) { + request.on('httpHeaders', function (statusCode, headers, resp) { if (statusCode >= 300) { handleError(new Error("http status code " + statusCode)); return; @@ -471,14 +471,14 @@ Client.prototype.downloadFile = function(params) { outStream.on('error', handleError); downloader.progressTotal = 0 downloader.progressAmount = -1; - request.on('httpData', function(chunk) { + request.on('httpData', function (chunk) { downloader.progressTotal += chunk.length; downloader.progressAmount += chunk.length; downloader.emit('progress'); outStream.write(chunk); }) - request.on('httpDone', function() { + request.on('httpDone', function () { if (errorOccurred) return; downloader.progressAmount += 1; downloader.emit('progress'); @@ -495,14 +495,14 @@ Client.prototype.downloadFile = function(params) { var eTagCount = getETagCount(eTag); var outStream = fs.createWriteStream(localFile); - var multipartETag = new MultipartETag({size: contentLength, count: eTagCount}); + var multipartETag = new MultipartETag({ size: contentLength, count: eTagCount }); var httpStream = resp.httpResponse.createUnbufferedStream(); httpStream.on('error', handleError); outStream.on('error', handleError); - hashCheckPend.go(function(cb) { - multipartETag.on('end', function() { + hashCheckPend.go(function (cb) { + multipartETag.on('end', function () { if (multipartETag.bytes !== contentLength) { handleError(new Error("Downloaded size does not match Content-Length")); return; @@ -514,11 +514,11 @@ Client.prototype.downloadFile = function(params) { cb(); }); }); - multipartETag.on('progress', function() { + multipartETag.on('progress', function () { downloader.progressAmount = multipartETag.bytes; downloader.emit('progress'); }); - outStream.on('close', function() { + outStream.on('close', function () { if (errorOccurred) return; hashCheckPend.wait(cb); }); @@ -549,7 +549,7 @@ Client.prototype.downloadFile = function(params) { * - MaxKeys: null, * - Prefix: prefix, */ -Client.prototype.listObjects = function(params) { +Client.prototype.listObjects = function (params) { var self = this; var ee = new EventEmitter(); var s3Details = extend({}, params.s3Params); @@ -559,7 +559,7 @@ Client.prototype.listObjects = function(params) { ee.progressAmount = 0; ee.objectsFound = 0; ee.dirsFound = 0; - findAllS3Objects(s3Details.Marker, s3Details.Prefix, function(err, data) { + findAllS3Objects(s3Details.Marker, s3Details.Prefix, function (err, data) { if (err) { ee.emit('error', err); return; @@ -567,7 +567,7 @@ Client.prototype.listObjects = function(params) { ee.emit('end'); }); - ee.abort = function() { + ee.abort = function () { abort = true; }; @@ -575,7 +575,7 @@ Client.prototype.listObjects = function(params) { function findAllS3Objects(marker, prefix, cb) { if (abort) return; - doWithRetry(listObjects, self.s3RetryCount, self.s3RetryDelay, function(err, data) { + doWithRetry(listObjects, self.s3RetryCount, self.s3RetryDelay, function (err, data) { if (abort) return; if (err) return cb(err); @@ -596,7 +596,7 @@ Client.prototype.listObjects = function(params) { pend.go(findNext1000); } - pend.wait(function(err) { + pend.wait(function (err) { cb(err); }); @@ -607,7 +607,7 @@ Client.prototype.listObjects = function(params) { function recurse(dirObj) { var prefix = dirObj.Prefix; - pend.go(function(cb) { + pend.go(function (cb) { findAllS3Objects(null, prefix, cb); }); } @@ -615,14 +615,14 @@ Client.prototype.listObjects = function(params) { function listObjects(cb) { if (abort) return; - self.s3Pend.go(function(pendCb) { + self.s3Pend.go(function (pendCb) { if (abort) { pendCb(); return; } s3Details.Marker = marker; s3Details.Prefix = prefix; - self.s3.listObjects(s3Details, function(err, data) { + self.s3.listObjects(s3Details, function (err, data) { pendCb(); if (abort) return; cb(err, data); @@ -639,15 +639,15 @@ Client.prototype.listObjects = function(params) { * - Bucket (required) * - Key (required) */ -Client.prototype.uploadDir = function(params) { +Client.prototype.uploadDir = function (params) { return syncDir(this, params, true); }; -Client.prototype.downloadDir = function(params) { +Client.prototype.downloadDir = function (params) { return syncDir(this, params, false); }; -Client.prototype.deleteDir = function(s3Params) { +Client.prototype.deleteDir = function (s3Params) { var self = this; var ee = new EventEmitter(); var bucket = s3Params.Bucket; @@ -663,10 +663,10 @@ Client.prototype.deleteDir = function(s3Params) { var pend = new Pend(); ee.progressAmount = 0; ee.progressTotal = 0; - finder.on('error', function(err) { + finder.on('error', function (err) { ee.emit('error', err); }); - finder.on('data', function(objects) { + finder.on('data', function (objects) { ee.progressTotal += objects.Contents.length; ee.emit('progress'); if (objects.Contents.length > 0) { @@ -683,31 +683,31 @@ Client.prototype.deleteDir = function(s3Params) { MFA: mfa, }; var deleter = self.deleteObjects(params); - deleter.on('error', function(err) { + deleter.on('error', function (err) { finder.abort(); ee.emit('error', err); }); - deleter.on('end', function() { + deleter.on('end', function () { ee.progressAmount += objects.Contents.length; ee.emit('progress'); cb(); }); } }); - finder.on('end', function() { - pend.wait(function() { + finder.on('end', function () { + pend.wait(function () { ee.emit('end'); }); }); return ee; }; -Client.prototype.copyObject = function(_s3Params) { +Client.prototype.copyObject = function (_s3Params) { var self = this; var ee = new EventEmitter(); var s3Params = extend({}, _s3Params); delete s3Params.MFA; - doWithRetry(doCopyWithPend, self.s3RetryCount, self.s3RetryDelay, function(err, data) { + doWithRetry(doCopyWithPend, self.s3RetryCount, self.s3RetryDelay, function (err, data) { if (err) { ee.emit('error', err); } else { @@ -715,8 +715,8 @@ Client.prototype.copyObject = function(_s3Params) { } }); function doCopyWithPend(cb) { - self.s3Pend.go(function(pendCb) { - doTheCopy(function(err, data) { + self.s3Pend.go(function (pendCb) { + doTheCopy(function (err, data) { pendCb(); cb(err, data); }); @@ -728,16 +728,16 @@ Client.prototype.copyObject = function(_s3Params) { return ee; }; -Client.prototype.moveObject = function(s3Params) { +Client.prototype.moveObject = function (s3Params) { var self = this; var ee = new EventEmitter(); var copier = self.copyObject(s3Params); var copySource = s3Params.CopySource; var mfa = s3Params.MFA; - copier.on('error', function(err) { + copier.on('error', function (err) { ee.emit('error', err); }); - copier.on('end', function(data) { + copier.on('end', function (data) { ee.emit('copySuccess', data); var slashIndex = copySource.indexOf('/'); var sourceBucket = copySource.substring(0, slashIndex); @@ -755,28 +755,28 @@ Client.prototype.moveObject = function(s3Params) { MFA: mfa, }; var deleter = self.deleteObjects(deleteS3Params); - deleter.on('error', function(err) { + deleter.on('error', function (err) { ee.emit('error', err); }); var deleteData; - deleter.on('data', function(data) { + deleter.on('data', function (data) { deleteData = data; }); - deleter.on('end', function() { + deleter.on('end', function () { ee.emit('end', deleteData); }); }); return ee; }; -Client.prototype.downloadBuffer = function(s3Params) { +Client.prototype.downloadBuffer = function (s3Params) { var self = this; var downloader = new EventEmitter(); s3Params = extend({}, s3Params); downloader.progressAmount = 0; - doWithRetry(doDownloadWithPend, self.s3RetryCount, self.s3RetryDelay, function(err, buffer) { + doWithRetry(doDownloadWithPend, self.s3RetryCount, self.s3RetryDelay, function (err, buffer) { if (err) { downloader.emit('error', err); return; @@ -787,8 +787,8 @@ Client.prototype.downloadBuffer = function(s3Params) { return downloader; function doDownloadWithPend(cb) { - self.s3Pend.go(function(pendCb) { - doTheDownload(function(err, buffer) { + self.s3Pend.go(function (pendCb) { + doTheDownload(function (err, buffer) { pendCb(); cb(err, buffer); }); @@ -799,7 +799,7 @@ Client.prototype.downloadBuffer = function(s3Params) { var errorOccurred = false; var request = self.s3.getObject(s3Params); var hashCheckPend = new Pend(); - request.on('httpHeaders', function(statusCode, headers, resp) { + request.on('httpHeaders', function (statusCode, headers, resp) { if (statusCode >= 300) { handleError(new Error("http status code " + statusCode)); return; @@ -813,14 +813,14 @@ Client.prototype.downloadBuffer = function(s3Params) { var eTagCount = getETagCount(eTag); var outStream = new StreamSink(); - var multipartETag = new MultipartETag({size: contentLength, count: eTagCount}); + var multipartETag = new MultipartETag({ size: contentLength, count: eTagCount }); var httpStream = resp.httpResponse.createUnbufferedStream(); httpStream.on('error', handleError); outStream.on('error', handleError); - hashCheckPend.go(function(cb) { - multipartETag.on('end', function() { + hashCheckPend.go(function (cb) { + multipartETag.on('end', function () { if (multipartETag.bytes !== contentLength) { handleError(new Error("Downloaded size does not match Content-Length")); return; @@ -832,13 +832,13 @@ Client.prototype.downloadBuffer = function(s3Params) { cb(); }); }); - multipartETag.on('progress', function() { + multipartETag.on('progress', function () { downloader.progressAmount = multipartETag.bytes; downloader.emit('progress'); }); - outStream.on('finish', function() { + outStream.on('finish', function () { if (errorOccurred) return; - hashCheckPend.wait(function() { + hashCheckPend.wait(function () { cb(null, outStream.toBuffer()); }); }); @@ -859,19 +859,19 @@ Client.prototype.downloadBuffer = function(s3Params) { } }; -Client.prototype.downloadStream = function(s3Params) { +Client.prototype.downloadStream = function (s3Params) { var self = this; var downloadStream = new PassThrough(); s3Params = extend({}, s3Params); - doDownloadWithPend(function(err) { + doDownloadWithPend(function (err) { if (err) downloadStream.emit('error', err); }); return downloadStream; function doDownloadWithPend(cb) { - self.s3Pend.go(function(pendCb) { - doTheDownload(function(err) { + self.s3Pend.go(function (pendCb) { + doTheDownload(function (err) { pendCb(); cb(err); }); @@ -882,7 +882,7 @@ Client.prototype.downloadStream = function(s3Params) { var errorOccurred = false; var request = self.s3.getObject(s3Params); var hashCheckPend = new Pend(); - request.on('httpHeaders', function(statusCode, headers, resp) { + request.on('httpHeaders', function (statusCode, headers, resp) { if (statusCode >= 300) { handleError(new Error("http status code " + statusCode)); return; @@ -892,7 +892,7 @@ Client.prototype.downloadStream = function(s3Params) { httpStream.on('error', handleError); - downloadStream.on('finish', function() { + downloadStream.on('finish', function () { if (errorOccurred) return; cb(); }); @@ -977,7 +977,7 @@ function syncDir(self, params, directionIsToS3) { }; var deleter = self.deleteObjects(params); deleter.on('error', handleError); - deleter.on('end', function() { + deleter.on('end', function () { if (fatalError) return; ee.deleteAmount += thisObjectsToDelete.length; ee.emit('progress'); @@ -1007,9 +1007,8 @@ function syncDir(self, params, directionIsToS3) { // if we don't have any pending deletes or uploads, we're actually done flushDeletes(); if (ee.deleteAmount >= ee.deleteTotal && - ee.progressAmount >= ee.progressTotal && - ee.activeTransfers === 0) - { + ee.progressAmount >= ee.progressTotal && + ee.activeTransfers === 0) { ee.emit('end'); // prevent checkDoMoreWork from doing any more work fatalError = true; @@ -1043,7 +1042,7 @@ function syncDir(self, params, directionIsToS3) { uploadLocalFile(); } else if (localFileStat.s3Path > s3Object.key) { deleteS3Object(); - } else if (!compareMultipartETag(s3Object.ETag, localFileStat.multipartETag)){ + } else if (!compareMultipartETag(s3Object.ETag, localFileStat.multipartETag)) { // both file cursor and s3 cursor should increment s3ObjectCursor += 1; uploadLocalFile(); @@ -1059,7 +1058,7 @@ function syncDir(self, params, directionIsToS3) { deleteLocalFile(); } else if (localFileStat.s3Path > s3Object.key) { downloadS3Object(); - } else if (!compareMultipartETag(s3Object.ETag, localFileStat.multipartETag)){ + } else if (!compareMultipartETag(s3Object.ETag, localFileStat.multipartETag)) { // both file cursor and s3 cursor should increment localFileCursor += 1; downloadS3Object(); @@ -1071,7 +1070,7 @@ function syncDir(self, params, directionIsToS3) { function deleteLocalDir() { var fullPath = path.join(localDir, localFileStat.path); ee.deleteTotal += 1; - rimraf(fullPath, function(err) { + rimraf(fullPath, function (err) { if (fatalError) return; if (err && err.code !== 'ENOENT') return handleError(err); ee.deleteAmount += 1; @@ -1086,7 +1085,7 @@ function syncDir(self, params, directionIsToS3) { if (!deleteRemoved) return; ee.deleteTotal += 1; var fullPath = path.join(localDir, localFileStat.path); - fs.unlink(fullPath, function(err) { + fs.unlink(fullPath, function (err) { if (fatalError) return; if (err && err.code !== 'ENOENT') return handleError(err); ee.deleteAmount += 1; @@ -1129,14 +1128,14 @@ function syncDir(self, params, directionIsToS3) { ee.activeTransfers++; ee.emit('fileDownloadStart', fullPath, fullKey); downloader.on('error', handleError); - downloader.on('progress', function() { + downloader.on('progress', function () { if (fatalError) return; var delta = downloader.progressAmount - prevAmountDone; prevAmountDone = downloader.progressAmount; ee.progressAmount += delta; ee.emit('progress'); }); - downloader.on('end', function() { + downloader.on('end', function () { ee.activeTransfers--; ee.emit('fileDownloadEnd', fullPath, fullKey); ee.emit('progress'); @@ -1187,7 +1186,7 @@ function syncDir(self, params, directionIsToS3) { ee.activeTransfers++; ee.emit('fileUploadStart', fullPath, fullKey); uploader.on('error', handleError); - uploader.on('progress', function() { + uploader.on('progress', function () { if (fatalError) return; var amountDelta = uploader.progressAmount - prevAmountDone; prevAmountDone = uploader.progressAmount; @@ -1199,7 +1198,7 @@ function syncDir(self, params, directionIsToS3) { ee.emit('progress'); }); - uploader.on('end', function() { + uploader.on('end', function () { ee.activeTransfers--; ee.emit('fileUploadEnd', fullPath, fullKey); ee.emit('progress'); @@ -1212,7 +1211,7 @@ function syncDir(self, params, directionIsToS3) { s3ObjectCursor += 1; setImmediate(checkDoMoreWork); if (!deleteRemoved) return; - objectsToDelete.push({Key: s3Object.Key}); + objectsToDelete.push({ Key: s3Object.Key }); ee.deleteTotal += 1; ee.emit('progress'); assert.ok(objectsToDelete.length <= 1000); @@ -1231,17 +1230,17 @@ function syncDir(self, params, directionIsToS3) { function findAllS3Objects() { var finder = self.listObjects(listObjectsParams); finder.on('error', handleError); - finder.on('data', function(data) { + finder.on('data', function (data) { if (fatalError) return; ee.objectsFound += data.Contents.length; ee.emit('progress'); - data.Contents.forEach(function(object) { + data.Contents.forEach(function (object) { object.key = object.Key.substring(prefix.length); allS3Objects.push(object); }); checkDoMoreWork(); }); - finder.on('end', function() { + finder.on('end', function () { if (fatalError) return; ee.doneFindingObjects = true; ee.emit('progress'); @@ -1250,14 +1249,14 @@ function syncDir(self, params, directionIsToS3) { } function startFindAllFiles() { - findAllFiles(function(err) { + findAllFiles(function (err) { if (fatalError) return; if (err) return handleError(err); ee.doneFindingFiles = true; ee.emit('progress'); - allLocalFiles.sort(function(a, b) { + allLocalFiles.sort(function (a, b) { if (a.s3Path < b.s3Path) { return -1; } else if (a.s3Path > b.s3Path) { @@ -1293,12 +1292,12 @@ function syncDir(self, params, directionIsToS3) { var multipartETag = new MultipartETag(); inStream.on('error', handleError); var prevBytes = 0; - multipartETag.on('progress', function() { + multipartETag.on('progress', function () { var delta = multipartETag.bytes - prevBytes; prevBytes = multipartETag.bytes; ee.progressMd5Amount += delta; }); - multipartETag.on('end', function() { + multipartETag.on('end', function () { if (fatalError) return; localFileStat.multipartETag = multipartETag; checkDoMoreWork(); @@ -1314,7 +1313,7 @@ function syncDir(self, params, directionIsToS3) { function findAllFiles(cb) { var dirWithSlash = ensureSep(localDir); var walker = findit(dirWithSlash, finditOpts); - walker.on('error', function(err) { + walker.on('error', function (err) { walker.stop(); // when uploading, we don't want to delete based on a nonexistent source directory // but when downloading, the destination directory does not have to exist. @@ -1324,7 +1323,7 @@ function syncDir(self, params, directionIsToS3) { cb(err); } }); - walker.on('directory', function(dir, stat, stop, linkPath) { + walker.on('directory', function (dir, stat, stop, linkPath) { if (fatalError) return walker.stop(); // we only need to save directories when deleteRemoved is true // and we're syncing to disk from s3 @@ -1336,7 +1335,7 @@ function syncDir(self, params, directionIsToS3) { stat.multipartETag = new MultipartETag(); allLocalFiles.push(stat); }); - walker.on('file', function(file, stat, linkPath) { + walker.on('file', function (file, stat, linkPath) { if (fatalError) return walker.stop(); var relPath = path.relative(localDir, linkPath || file); stat.path = relPath; @@ -1346,7 +1345,7 @@ function syncDir(self, params, directionIsToS3) { ee.emit('progress'); allLocalFiles.push(stat); }); - walker.on('end', function() { + walker.on('end', function () { cb(); }); } @@ -1370,7 +1369,7 @@ function doWithRetry(fn, tryCount, delay, cb) { tryOnce(); function tryOnce() { - fn(function(err, result) { + fn(function (err, result) { if (err) { if (err.retryable === false) { cb(err); @@ -1433,11 +1432,11 @@ function encodeSpecialCharacters(filename) { } function getPublicUrl(bucket, key, bucketLocation, endpoint) { - var nonStandardBucketLocation = (bucketLocation && bucketLocation !== 'us-east-1'); - var hostnamePrefix = nonStandardBucketLocation ? ("s3-" + bucketLocation) : "s3"; + var bucketLocation = bucketLocation ? bucketLocation : 'us-east-1'; + var hostnamePrefix = "s3"; var parts = { protocol: "https:", - hostname: hostnamePrefix + '.' + (endpoint || "amazonaws.com"), + hostname: hostnamePrefix + '.' + bucketLocation + "." + (endpoint || "amazonaws.com"), pathname: "/" + bucket + "/" + encodeSpecialCharacters(key), }; return url.format(parts); @@ -1461,7 +1460,7 @@ function toNativeSep(str) { } function quotemeta(str) { - return String(str).replace(/(\W)/g, '\\$1'); + return String(str).replace(/(\W)/g, '\\$1'); } function smallestPartSizeFromFileSize(fileSize) { diff --git a/package.json b/package.json index e26cce4..8f17522 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "ncp": "~1.0.1" }, "dependencies": { - "aws-sdk": "~2.4.9", + "aws-sdk": "^2", "fd-slicer": "~1.0.0", "findit2": "~2.2.3", "graceful-fs": "~4.1.4",