title: node.js: How to wait until "unzip" is complete before trying to parse contents
body: <p>Creating a node.js to auto-download a zip file, containing one text file with a list of 5000 UserID's and Usernames (CSV). An example text file would be:<br>
   <code>12345,JSmith</code><br>
  <code>728422,YPatel</code></p>
  
  <p>Every time I run this, I get different results. 
  I think the likely cause is I am attempting to parse the unzipped file, before unzip has finished saving to disk.</p>
  
  <p>Is there a way to either asynchronously parse the unzipped data, or at least wait until unzip is complete, before trying to parse the extracted file? (I am also happy to do this whole process from memory, and avoid disk)</p>
  
  <p>I am very new to node.js.</p>
  
  <pre><code>function downloadAndUnzip(URL, doWhenFinished){
      require('request')
      .get(URL)
      .on('error', function(error) {
          console.log(error)
      })
      .on('end', doWhenFinished)
      .pipe(require('unzip').Extract({path:'./'}))
  }
  
  var parseFile = function(){
      var fs = require('fs')
      var array = 
  
  fs.readFileSync('usernames.txt').toString().split("\n\r");
          for (i in array) {
                  user = array[i].split(",");
                  console.log("UserID: " + user[0] + " Username: " + user[1]);
              }
          }
      }
  
  DownloadAndUnzip(URL, parseFile())
  </code></pre>