lib/middleware/submissions.js
function _processExportResponse(csvs, res, next) {
  var zip = archiver('zip');

  // convert csv entries to in-memory zip file and stream response
  res.setHeader('Content-type', 'application/zip');
  res.setHeader('Content-disposition', 'attachment; filename=submissions.zip');
  zip.pipe(res);

  for (var form in csvs) { // eslint-disable-line guard-for-in
    var csv = csvs[form];
    zip.append(csv, {name: form + '.csv'});
  }

  var respSent = false;
  zip.on('error', function(err) {
    logger.error("_processExportResponse ", {error: err});
    if (err) {
      if (!respSent) {
        respSent = true;
        return next(err);
      }
    }
  });

  zip.finalize(function(err) {
    if (err) {
      logger.error("_processExportResponse finalize", {error: err});
      if (!respSent) {
        respSent = true;
        return next(err);
      }

      logger.debug("_processExportResponse finalize headers sent");
    }

    logger.debug("_processExportResponse finalize finished");
  });
}
function _processExportResponse(csvs, res, next) {
  var zip = archiver('zip');

  // convert csv entries to in-memory zip file and stream response
  res.setHeader('Content-type', 'application/zip');
  res.setHeader('Content-disposition', 'attachment; filename=submissions.zip');
  zip.pipe(res);

  for (var form in csvs) { // eslint-disable-line guard-for-in
    var csv = csvs[form];
    zip.append(csv, {name: form + '.csv'});
  }

  var respSent = false;
  zip.on('error', function(err) {
    logger.error("_processExportResponse ", {error: err});
    if (err) {
      if (!respSent) {
        respSent = true;
        return next(err);
      }
    }
  });

  zip.finalize(function(err) {
    if (err) {
      logger.error("_processExportResponse finalize", {error: err});
      if (!respSent) {
        respSent = true;
        return next(err);
      }

      logger.debug("_processExportResponse finalize headers sent");
    }

    logger.debug("_processExportResponse finalize finished");
  });
}
function _processExportResponse ( csvs , res , next ) { var zip = archiver ( 'zip' ) ; // convert csv entries to in-memory zip file and stream response res . setHeader ( 'Content-type' , 'application/zip' ) ; res . setHeader ( 'Content-disposition' , 'attachment; filename=submissions.zip' ) ; zip . pipe ( res ) ; for ( var form in csvs ) { // eslint-disable-line guard-for-in var csv = csvs [ form ] ; zip . append ( csv , { name : form + '.csv' } ) ; } var respSent = false ; zip . on ( 'error' , function ( err ) { logger . error ( "_processExportResponse " , { error : err } ) ; if ( err ) { if ( ! respSent ) { respSent = true ; return next ( err ) ; } } } ) ; zip . finalize ( function ( err ) { if ( err ) { logger . error ( "_processExportResponse finalize" , { error : err } ) ; if ( ! respSent ) { respSent = true ; return next ( err ) ; } logger . debug ( "_processExportResponse finalize headers sent" ) ; } logger . debug ( "_processExportResponse finalize finished" ) ; } ) ; }
Function for processing submissions into a zip file containing csv files.
Function for processing submissions into a zip file containing csv files .