Open copyandexecute opened 3 years ago
I have the same problem.... I try to receive 2 files in sequence, but the download event does not work intermittently...ㅠㅠ SOMEBODY HELPME
This thing is just horrendously broken as everything electron.
Because of the unbelievable crappiness of electron that manages to f*ck up even a most basic task like downloading a file, I have come up with this nodejs
function that I use instead. Electron must be the only technology that manages to be even crappier than Node.js itself which is an incredible achievement in its own right, but whatever.
async function downloadFile(destPath, url) {
let cookies = await session.defaultSession.cookies.get({}),
header = cookies.map(c => `${c.name}=${c.value}`).join('; '),
_fs = require('fs'),
_http = require('http');
return new Promise((resolve, reject) => {
_http.get(url, { headers: { 'Cookie': header } }, ret => {
let file = _fs.createWriteStream(destPath);
ret.pipe(file);
file.on('finish', () => {
file.close();
resolve(destPath);
});
}).on('error', err => {
reject(err.message);
});
});
}
I think this is due to it spawning two listeners if you look at the source.
Give my package a try where it does handle multiple downloads:
My library support Multiple downloads are handled properly and report individual progress. You are also able to cancel / pause / resume as well. Easy to use
After I click on my button the download multiplies each team