remove pipeline() chain

it cannot be chained afaict
This commit is contained in:
Girish Ramakrishnan
2023-08-29 17:44:02 +05:30
parent 35828fe1c7
commit 7fe2de448e
2 changed files with 16 additions and 35 deletions

View File

@@ -13,11 +13,13 @@ const assert = require('assert'),
async = require('async'),
BoxError = require('../boxerror.js'),
DataLayout = require('../datalayout.js'),
{ DecryptStream } = require('../hush.js'),
debug = require('debug')('box:backupformat/rsync'),
fs = require('fs'),
hush = require('../hush.js'),
once = require('../once.js'),
path = require('path'),
ProgressStream = require('../progress-stream.js'),
promiseRetry = require('../promise-retry.js'),
safe = require('safetydance'),
storage = require('../storage.js'),
@@ -182,17 +184,27 @@ function downloadDir(backupConfig, backupFilePath, dataLayout, progressCallback,
throw downloadError;
}
const destStream = hush.createWriteStream(destFilePath, backupConfig.encryption);
destStream.on('progress', function (progress) {
const ps = new ProgressStream({ interval: 10000 }); // display a progress every 10 seconds
ps.on('progress', function (progress) {
const transferred = Math.round(progress.transferred/1024/1024), speed = Math.round(progress.speed/1024/1024);
if (!transferred && !speed) return progressCallback({ message: `Downloading ${entry.fullPath}` }); // 0M@0MBps looks wrong
progressCallback({ message: `Downloading ${entry.fullPath}: ${transferred}M@${speed}MBps` });
});
const destStream = fs.createWriteStream(destFilePath);
const streams = [ sourceStream, ps ];
if (backupConfig.encryption) {
const decryptStream = new DecryptStream(backupConfig.encryption);
streams.push(decryptStream);
}
streams.push(destStream);
progressCallback({ message: `Downloading ${entry.fullPath} to ${destFilePath}` });
const [pipelineError] = await safe(stream.promises.pipeline(sourceStream, destStream));
const [pipelineError] = await safe(stream.promises.pipeline(streams));
if (pipelineError) {
progressCallback({ message: `Download error ${entry.fullPath} to ${destFilePath}: ${pipelineError.message}` });
throw pipelineError;