summaryrefslogtreecommitdiff
path: root/node_modules/archiver/lib/core.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/archiver/lib/core.js')
-rw-r--r--node_modules/archiver/lib/core.js111
1 files changed, 62 insertions, 49 deletions
diff --git a/node_modules/archiver/lib/core.js b/node_modules/archiver/lib/core.js
index 6103d43e4..9bb80711c 100644
--- a/node_modules/archiver/lib/core.js
+++ b/node_modules/archiver/lib/core.js
@@ -9,6 +9,8 @@ var fs = require('fs');
var glob = require('glob');
var async = require('async');
var _ = require('lodash');
+var path = require('path');
+var walkdir = require('walkdir');
var util = require('archiver-utils');
var inherits = require('util').inherits;
@@ -16,6 +18,10 @@ var Transform = require('readable-stream').Transform;
var win32 = process.platform === 'win32';
+if (process._loggedBulkDeprecation === undefined) {
+ process._loggedBulkDeprecation = false;
+}
+
/**
* @constructor
* @param {String} format The archive format to use.
@@ -58,8 +64,6 @@ var Archiver = function(format, options) {
};
this._streams = [];
-
- this._loggedBulkDeprecation = false;
};
inherits(Archiver, Transform);
@@ -557,8 +561,8 @@ Archiver.prototype.append = function(source, data) {
* @return {this}
*/
Archiver.prototype.bulk = function(mappings) {
- if (!this._loggedBulkDeprecation) {
- this._loggedBulkDeprecation = true;
+ if (process._loggedBulkDeprecation === false) {
+ process._loggedBulkDeprecation = true;
var warning = 'Archiver.bulk() deprecated since 0.21.0';
if (typeof process !== 'undefined' && typeof process.emitWarning !== 'undefined') {
process.emitWarning(warning, 'DeprecationWarning');
@@ -655,38 +659,43 @@ Archiver.prototype.directory = function(dirpath, destpath, data) {
data = {};
}
- var self = this;
+ function onWalkPath(filepath, stats){
+ var entryData = _.extend({}, data);
+ entryData.name = path.relative(dirpath, filepath).replace(/\\/g, '/');
+ entryData.prefix = destpath;
+ entryData.stats = stats;
- 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');
- }
- }
- } catch(e) {
- self.emit('error', e);
- return;
- }
+ try {
+ if (dataFunction) {
+ entryData = dataFunction(entryData);
- self._append(file.path, entryData);
- });
+ if (typeof entryData !== 'object') {
+ throw new Error('directory: invalid data returned from custom function');
+ }
+ }
+ } catch(e) {
+ this.emit('error', e);
+ return;
}
- self._pending--;
- self._maybeFinalize();
- });
+ this._append(filepath, entryData);
+ }
+
+ function onWalkEnd() {
+ this._pending--;
+ this._maybeFinalize();
+ }
+
+ function onWalkError(err) {
+ this.emit('error', 'directory: ' + err);
+ }
+
+ var walker = walkdir(dirpath);
+
+ walker.on('error', onWalkError.bind(this));
+ walker.on('directory', onWalkPath.bind(this));
+ walker.on('file', onWalkPath.bind(this));
+ walker.on('end', onWalkEnd.bind(this));
return this;
};
@@ -736,26 +745,30 @@ Archiver.prototype.glob = function(pattern, options, data) {
stat: false
});
- var globber = glob(pattern, options, function(err, files) {
- if (err) {
- this.emit('error', err);
- return this;
- }
+ function onGlobEnd() {
+ this._pending--;
+ this._maybeFinalize();
+ }
- files.forEach(function(file) {
- entryData = _.extend({}, data);
+ function onGlobError(err) {
+ this.emit('error', 'glob: ' + err);
+ }
- if (options.cwd) {
- entryData.name = file;
- file = globber._makeAbs(file);
- }
+ function onGlobMatch(match){
+ entryData = _.extend({}, data);
- this._append(file, entryData);
- }, this);
+ if (options.cwd) {
+ entryData.name = match;
+ match = globber._makeAbs(match);
+ }
- this._pending--;
- this._maybeFinalize();
- }.bind(this));
+ this._append(match, entryData);
+ }
+
+ var globber = glob(pattern, options);
+ globber.on('error', onGlobError.bind(this));
+ globber.on('match', onGlobMatch.bind(this));
+ globber.on('end', onGlobEnd.bind(this));
return this;
};
@@ -890,4 +903,4 @@ module.exports = Archiver;
* when working with methods like `directory` or `glob`.
* @property {fs.Stats} [stats] Sets the fs stat data for this entry allowing
* for reduction of fs stat calls when stat data is already known.
- */ \ No newline at end of file
+ */