0

I'm downloading multiple files parallel with Javascript by using request, pipe and createWriteStream:

for(let i = 0; i < urls.length; i++) {
   let r = request(urls[i]).pipe(fs.createWriteStream(fn[i]))

   r.on('close', (() => {
      console.log(filenamewhichiscurrentlyclosed?)
   }))
}

How can I get the filename from the file that just closed? I can't use an index (fn[i]) because the downloads take different times.

Thanks!

PowerNow
  • 363
  • 1
  • 2
  • 15

0 Answers0