How to use the archiver-utils.walkdir function in archiver-utils

To help you get started, we’ve selected a few archiver-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github appcelerator / titanium_mobile / node_modules / archiver / lib / core.js View on Github external
destpath = '';
  } else if (typeof destpath !== 'string'){
    destpath = dirpath;
  }

  var dataFunction = false;
  if (typeof data === 'function') {
    dataFunction = data;
    data = {};
  } else if (typeof data !== 'object') {
    data = {};
  }

  var self = this;

  util.walkdir(dirpath, function(err, results) {
    if (err) {
      self.emit('error', err);
    } else {
      results.forEach(function(file) {
        var entryData = _.extend({}, data);
        entryData.name = file.relative;
        entryData.prefix = destpath;
        entryData.stats = file.stats;

        try {
          if (dataFunction) {
            entryData = dataFunction(entryData);

            if (typeof entryData !== 'object') {
              throw new Error('directory: invalid data returned from custom function');
            }