Do a multipart download for slow internet connections

Fixes #317
This commit is contained in:
Girish Ramakrishnan
2017-04-27 11:50:16 -07:00
parent 6cbf64b88e
commit e5c42f2b90
4 changed files with 14 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ var assert = require('assert'),
once = require('once'),
PassThrough = require('stream').PassThrough,
path = require('path'),
S3BlockReadStream = require('s3-block-read-stream'),
targz = require('./targz.js');
// test only
@@ -125,9 +126,9 @@ function restore(apiConfig, backupId, destination, callback) {
var s3 = new AWS.S3(credentials);
var s3get = s3.getObject(params).createReadStream();
var multipartDownload = new S3BlockReadStream(s3, params, { blockSize: 64 * 1024 * 1024, logCallback: debug });
s3get.on('error', function (error) {
multipartDownload.on('error', function (error) {
// TODO ENOENT for the mock, fix upstream!
if (error.code === 'NoSuchKey' || error.code === 'ENOENT') return callback(new BackupsError(BackupsError.NOT_FOUND));
@@ -135,7 +136,7 @@ function restore(apiConfig, backupId, destination, callback) {
callback(new BackupsError(BackupsError.EXTERNAL_ERROR, error.message));
});
targz.extract(s3get, destination, apiConfig.key || null, callback);
targz.extract(multipartDownload, destination, apiConfig.key || null, callback);
});
}