Add progress-stream for upload/download progress
This commit is contained in:
@@ -25,6 +25,7 @@ var assert = require('assert'),
|
||||
mkdirp = require('mkdirp'),
|
||||
once = require('once'),
|
||||
path = require('path'),
|
||||
progress = require('progress-stream'),
|
||||
tar = require('tar-fs'),
|
||||
zlib = require('zlib');
|
||||
|
||||
@@ -96,6 +97,7 @@ function backup(apiConfig, backupId, sourceDirectories, callback) {
|
||||
|
||||
var gzip = zlib.createGzip({});
|
||||
var encrypt = crypto.createCipher('aes-256-cbc', apiConfig.key || '');
|
||||
var progressStream = progress({ time: 10000 }); // display a progress every 10 seconds
|
||||
|
||||
pack.on('error', function (error) {
|
||||
console.error('[%s] backup: tar stream error.', backupId, error);
|
||||
@@ -112,12 +114,16 @@ function backup(apiConfig, backupId, sourceDirectories, callback) {
|
||||
callback(new BackupsError(BackupsError.EXTERNAL_ERROR, error.message));
|
||||
});
|
||||
|
||||
pack.pipe(gzip).pipe(encrypt);
|
||||
progressStream.on('progress', function(progress) {
|
||||
debug('[%s] backup: %s @ %s', backupId, Math.round(progress.transferred/1024/1024) + 'M', Math.round(progress.speed/1024/1024) + 'Mbps');
|
||||
});
|
||||
|
||||
pack.pipe(gzip).pipe(encrypt).pipe(progressStream);
|
||||
|
||||
var params = {
|
||||
Bucket: apiConfig.bucket,
|
||||
Key: backupFilePath,
|
||||
Body: encrypt
|
||||
Body: progressStream
|
||||
};
|
||||
|
||||
var s3 = new AWS.S3(credentials);
|
||||
@@ -158,6 +164,7 @@ function restore(apiConfig, backupId, destination, callback) {
|
||||
var s3get = s3.getObject(params).createReadStream();
|
||||
var decrypt = crypto.createDecipher('aes-256-cbc', apiConfig.key || '');
|
||||
var gunzip = zlib.createGunzip({});
|
||||
var progressStream = progress({ time: 10000 }); // display a progress every 10 seconds
|
||||
var extract = tar.extract(destination);
|
||||
|
||||
s3get.on('error', function (error) {
|
||||
@@ -168,6 +175,10 @@ function restore(apiConfig, backupId, destination, callback) {
|
||||
callback(new BackupsError(BackupsError.EXTERNAL_ERROR, error.message));
|
||||
});
|
||||
|
||||
progressStream.on('progress', function(progress) {
|
||||
debug('[%s] restore: %s @ %s', backupId, Math.round(progress.transferred/1024/1024) + 'M', Math.round(progress.speed/1024/1024) + 'Mbps');
|
||||
});
|
||||
|
||||
decrypt.on('error', function (error) {
|
||||
console.error('[%s] restore: decipher stream error.', error);
|
||||
callback(new BackupsError(BackupsError.EXTERNAL_ERROR, error.message));
|
||||
@@ -188,7 +199,7 @@ function restore(apiConfig, backupId, destination, callback) {
|
||||
callback(null);
|
||||
});
|
||||
|
||||
s3get.pipe(decrypt).pipe(gunzip).pipe(extract);
|
||||
s3get.pipe(progressStream).pipe(decrypt).pipe(gunzip).pipe(extract);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user