title: How to fetch the image files from a server and zip it in sailsjs
body: <p>I want to zip all the images from s3 urls. I am doing it on server side on sailsjs framework.</p>
  
  <p>I tried using axios to download the images and used 'zipdir'. The images are getting downloaded in temp folder. But its not getting zipped properly.</p>
  
  <pre><code>this.downloadFiles = function (req, res) {
      var resObj = {}
      async.waterfall([
          this.createFolder.bind(undefined, req),
          this.downloadFilesAxios.bind(undefined, req),
          this.zipTheFiles.bind(undefined, req)
      ], function final(err, result) {
          if (err) {
              console.log('SOME ERROR', err);
              resObj.statusCode = err.statusCode || 500;
          } else {
              resObj.statusCode = 200;
              resObj.result = result.questionList;
          }
          console.log('------', resObj.statusCode)
          resObj.messageKey = sails.config.statusCode[resObj.statusCode].key;
          resObj.message = sails.config.statusCode[resObj.statusCode].message;
          return res.send(resObj);
      });
  };
  
  
  
  }
  
  this.downloadFilesAxios = function (req, obj, callback) {
      SurveyDocs.find({ surveyId: req.body.surveyId })
          .exec(function (err, docsDetails) {
              async.map(docsDetails, function (img, cb) {
                  const url = img.docS3Url;
  
                  let imageName = img.docFileName;
                  const path = Path.resolve(__dirname, "temp", imageName);
                  const writer = Fs.createWriteStream(path)
  
                  Axios({
                      method: 'get',
                      url: url,
                      responseType: 'stream'
                  })
                      .then(function (response) {
                          response.data.pipe(writer)
                      })
                  writer.on('finish', (done) =&gt; {
                      console.log('success!!!');
                      cb(null, null)
                  });
                  writer.on('error', (err) =&gt; {
                      console.log('failed!!!');
                      cb(err, null)
                  });
  
              }, (err, data) =&gt; {
                  if (err) {
                      console.log('errrr', err);
                  }
                  callback(null, obj);
              });
          })
  };
  
  this.zipTheFiles = function (req, obj, callback) {
      var surveyId = req.body.surveyId;
      var tempDir = 'assets/zip/' + surveyId + '.zip'
      zipdir('temp', { saveTo: tempDir }, function (err, buffer) {
          callback(null, obj);
      });
      callback(null, obj);
  }
  </code></pre>
  
  <p>Here I am getting a corrupt zip file. Please suggest the solution.</p>