fs: open the source stream using download()

This commit is contained in:
Girish Ramakrishnan
2018-07-27 15:15:55 -07:00
parent 737541f707
commit ba8a549235

View File

@@ -122,15 +122,18 @@ function downloadDir(apiConfig, backupFilePath, destDir) {
mkdirp(path.dirname(destFilePath), function (error) {
if (error) return callback(new BackupsError(BackupsError.EXTERNAL_ERROR, error.message));
let sourceStream = fs.createReadStream(sourceFilePath);
sourceStream.on('error', callback);
download(apiConfig, sourceFilePath, function (error, sourceStream) {
if (error) return callback(error);
let destStream = fs.createWriteStream(destFilePath);
destStream.on('error', callback);
sourceStream.on('error', callback);
events.emit('progress', `downloadDir: Copying ${sourceFilePath} to ${destFilePath}`);
let destStream = fs.createWriteStream(destFilePath);
destStream.on('error', callback);
sourceStream.pipe(destStream, { end: true }).on('finish', callback);
events.emit('progress', `downloadDir: Copying ${sourceFilePath} to ${destFilePath}`);
sourceStream.pipe(destStream, { end: true }).on('finish', callback);
});
});
}