server: pipe the download directly

This commit is contained in:
Daniel Cousens
2017-10-18 10:04:15 +11:00
parent afed82ceb7
commit ca617bbf8a
+2 -12
View File
@@ -101,24 +101,14 @@ var client = {
}
} else {
const tempFilename = `${hash}-${Date.now()}.tar`;
const tempFilePath = TemporaryStorage.getTempPath(tempFilename);
const archive = archiver('tar', {store: true});
const output = fs.createWriteStream(tempFilePath);
output.on('close', () => {
const filename = `${selectedTorrent.name}.tar`;
res.attachment(path.basename(filename));
res.download(tempFilePath, filename, () => {
TemporaryStorage.deleteFile(tempFilename);
});
});
archive.on('error', (error) => {
throw error;
});
archive.pipe(output);
res.attachment(`${selectedTorrent.name}.tar`);
archive.pipe(res);
filePathsToDownload.forEach((filePath) => {
const filename = path.basename(filePath);