lib/impl/exportForms.js
function writeFormsToZip(forms, callback) {
  var zip = archiver('zip')
    , metadata = {};

  metadata.exportCreated = new Date();
  metadata.files = {};

  function processForms() {
    // Process all forms
    _.each(forms, function(form) {
      // Update metadata on the fly
      updateMetadata(metadata, form);
      zip.append(JSON.stringify(form), {
        name: path.join(ZIP_SUBFOLDER_NAME, form.id + '.json')
      });
    });

    // Last step: write the metadata file in the root folder
    zip.append(JSON.stringify(metadata), {
      name: METADATA_FILE_NAME
    });

    zip.finalize();
  }

  process.nextTick(processForms);
  callback(null, zip);
}
function writeFormsToZip(forms, callback) {
  var zip = archiver('zip')
    , metadata = {};

  metadata.exportCreated = new Date();
  metadata.files = {};

  function processForms() {
    // Process all forms
    _.each(forms, function(form) {
      // Update metadata on the fly
      updateMetadata(metadata, form);
      zip.append(JSON.stringify(form), {
        name: path.join(ZIP_SUBFOLDER_NAME, form.id + '.json')
      });
    });

    // Last step: write the metadata file in the root folder
    zip.append(JSON.stringify(metadata), {
      name: METADATA_FILE_NAME
    });

    zip.finalize();
  }

  process.nextTick(processForms);
  callback(null, zip);
}
function writeFormsToZip ( forms , callback ) { var zip = archiver ( 'zip' ) , metadata = { } ; metadata . exportCreated = new Date ( ) ; metadata . files = { } ; function processForms ( ) { // Process all forms _ . each ( forms , function ( form ) { // Update metadata on the fly updateMetadata ( metadata , form ) ; zip . append ( JSON . stringify ( form ) , { name : path . join ( ZIP_SUBFOLDER_NAME , form . id + '.json' ) } ) ; } ) ; // Last step: write the metadata file in the root folder zip . append ( JSON . stringify ( metadata ) , { name : METADATA_FILE_NAME } ) ; zip . finalize ( ) ; } process . nextTick ( processForms ) ; callback ( null , zip ) ; }
Creates a zip stream and returns it in the callback. The zip archive that
is created will contain a metadata.json file and a subfolder `ZIP_SUBFOLDER_NAME`
where all the forms will be written to.

@param forms A collection of fully populated form objects
@param callback Invoked with the zip stream
Creates a zip stream and returns it in the callback . The zip archive that is created will contain a metadata . json file and a subfolder ZIP_SUBFOLDER_NAME where all the forms will be written to .