Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 50 additions & 3 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ var Archiver = function(format, options) {

Transform.call(this, options);

this._entries = [];
this._format = false;
this._module = false;
this._pending = 0;
this._pointer = 0;

this._entriesCount = 0;
this._entriesProcessedCount = 0;
this._fsEntriesTotalBytes = 0;
this._fsEntriesProcessedBytes = 0;

this._queue = async.queue(this._onQueueTask.bind(this), 1);
this._queue.drain = this._onQueueDrain.bind(this);

Expand Down Expand Up @@ -106,10 +110,17 @@ Archiver.prototype._append = function(filepath, data) {

data.sourcePath = filepath;
task.data = data;
this._entriesCount++;

if (data.stats && data.stats instanceof fs.Stats) {
task = this._updateQueueTaskWithStats(task, data.stats);
if (task) this._queue.push(task);
if (task) {
if (data.stats.size) {
this._fsEntriesTotalBytes += data.stats.size;
}

this._queue.push(task);
}
} else {
this._statQueue.push(task);
}
Expand Down Expand Up @@ -190,7 +201,26 @@ Archiver.prototype._moduleAppend = function(source, data, callback) {
* @type {EntryData}
*/
this.emit('entry', data);
this._entries.push(data);
this._entriesProcessedCount++;

if (data.stats && data.stats.size) {
this._fsEntriesProcessedBytes += data.stats.size;
}

/**
* @event Archiver#progress
* @type {ProgressData}
*/
this.emit('progress', {
entries: {
total: this._entriesCount,
processed: this._entriesProcessedCount
},
fs: {
totalBytes: this._fsEntriesTotalBytes,
processedBytes: this._fsEntriesProcessedBytes
}
});

setImmediate(callback);
}.bind(this));
Expand Down Expand Up @@ -399,8 +429,13 @@ Archiver.prototype._onStatQueueTask = function(task, callback) {
task = this._updateQueueTaskWithStats(task, stats);

if (task) {
if (stats.size) {
this._fsEntriesTotalBytes += stats.size;
}

this._queue.push(task);
}

setImmediate(callback);
}.bind(this));
};
Expand Down Expand Up @@ -528,6 +563,7 @@ Archiver.prototype.append = function(source, data) {
return this;
}

this._entriesCount++;
this._queue.push({
data: data,
source: source
Expand Down Expand Up @@ -808,6 +844,7 @@ Archiver.prototype.symlink = function(filepath, target) {
data.linkname = target.replace(/\\/g, '/');
data.sourceType = 'buffer';

this._entriesCount++;
this._queue.push({
data: data,
source: new Buffer(0)
Expand Down Expand Up @@ -877,3 +914,13 @@ module.exports = Archiver;
* @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.
*/

/**
* @typedef {Object} ProgressData
* @property {Object} entries
* @property {Number} entries.total Number of entries that have been appended.
* @property {Number} entries.processed Number of entries that have been processed.
* @property {Object} fs
* @property {Number} fs.totalBytes Number of bytes that have been appended. (based on fs.Stats)
* @property {Number} fs.processedBytes Number of bytes that have been processed. (based on fs.Stats)
*/