title: Using pipe to build a file from an async await https request
body: <p>Following the docs and a day's worth of research, I'm trying to use pipe to assemble an Excel spreadsheet returned by an API call. I get partway to saving it but the file is corrupted:</p>
  
  <pre><code>async function getWeeklyReport(queryString) {
  return new Promise((resolve, reject) =&gt; {
  request({
    url: 'https://reports.myApi.com/ReportCenter/Bookings',
    qs: queryString,
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json',
      'Authorization': 'Basic ' + new Buffer(process.env.apiEmail + ':' + process.env.apiPassword, 'utf8').toString('base64')
    }
  }, (error, response, body) =&gt; {
    if (error) {
      reject(error);
    } else {
      if (response.statusCode === 200) {
        resolve(body);
      } else if (response.statusCode === 409) {
        setTimeout(() =&gt; {
          resolve(getWeeklyReport(queryString));
        }, response.headers['Retry-After'] * 1000);
      } else {
        reject(response);
      }
    }
  }).pipe(fs.createWriteStream('test3.xlsm'));
  </code></pre>
  
  <p>});
  }</p>
  
  <p>What am I doing wrong here? test3 is created but the file is corrupted. Thanks!</p>