From d6ddb510cbd9a4bf00c4602f80391e52951132c9 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Sat, 17 Jun 2017 10:47:44 -0500 Subject: [PATCH 1/5] work on progress. --- lib/core.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/lib/core.js b/lib/core.js index d4d7a390a..5cef4bd1c 100644 --- a/lib/core.js +++ b/lib/core.js @@ -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); @@ -109,7 +113,15 @@ Archiver.prototype._append = function(filepath, data) { if (data.stats && data.stats instanceof fs.Stats) { task = this._updateQueueTaskWithStats(task, data.stats); - if (task) this._queue.push(task); + if (task) { + this._entriesCount++; + + if (data.stats.size) { + this._fsEntriesTotalBytes += data.stats.size; + } + + this._queue.push(task); + } } else { this._statQueue.push(task); } @@ -190,7 +202,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)); @@ -399,8 +430,15 @@ Archiver.prototype._onStatQueueTask = function(task, callback) { task = this._updateQueueTaskWithStats(task, stats); if (task) { + this._entriesCount++; + + if (stats.size) { + this._fsEntriesTotalBytes += stats.size; + } + this._queue.push(task); } + setImmediate(callback); }.bind(this)); }; @@ -528,6 +566,7 @@ Archiver.prototype.append = function(source, data) { return this; } + this._entriesCount++; this._queue.push({ data: data, source: source @@ -808,6 +847,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) @@ -877,3 +917,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 based on fs.Stats of appended entries. + * @property {Number} fs.processedBytes Number of bytes that hae been processed. + */ \ No newline at end of file From 27fcce8927dc9bfc735e3c443528fb7df1073673 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Sat, 17 Jun 2017 11:11:38 -0500 Subject: [PATCH 2/5] adjust docs [ci skip] --- lib/core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core.js b/lib/core.js index 5cef4bd1c..b037fbeb4 100644 --- a/lib/core.js +++ b/lib/core.js @@ -924,6 +924,6 @@ module.exports = Archiver; * @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 based on fs.Stats of appended entries. - * @property {Number} fs.processedBytes Number of bytes that hae been processed. + * @property {Number} fs.totalBytes Number of bytes that have been appended (based on fs.Stats). + * @property {Number} fs.processedBytes Number of bytes that hae been processed (based on fs.Stats). */ \ No newline at end of file From 0e0421ebbbbe6e74c4f042f1a1735aa22153b6b9 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Sat, 17 Jun 2017 11:12:08 -0500 Subject: [PATCH 3/5] adjust docs [ci skip] --- lib/core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core.js b/lib/core.js index b037fbeb4..f7d9b3b15 100644 --- a/lib/core.js +++ b/lib/core.js @@ -924,6 +924,6 @@ module.exports = Archiver; * @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 hae been processed (based on fs.Stats). + * @property {Number} fs.totalBytes Number of bytes that have been appended. (based on fs.Stats) + * @property {Number} fs.processedBytes Number of bytes that hae been processed. (based on fs.Stats) */ \ No newline at end of file From 994b8c198e10ba8f5edaa798e28f54563f389182 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Sat, 17 Jun 2017 11:12:51 -0500 Subject: [PATCH 4/5] adjust docs [ci skip] --- lib/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core.js b/lib/core.js index f7d9b3b15..bd4e6105e 100644 --- a/lib/core.js +++ b/lib/core.js @@ -925,5 +925,5 @@ module.exports = Archiver; * @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 hae been processed. (based on fs.Stats) + * @property {Number} fs.processedBytes Number of bytes that have been processed. (based on fs.Stats) */ \ No newline at end of file From d221f0c7ae7346764cc35bc5f8640d4c3f1f0a3a Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Sat, 17 Jun 2017 11:17:09 -0500 Subject: [PATCH 5/5] count entries in single location when using internal method. --- lib/core.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/core.js b/lib/core.js index bd4e6105e..f99260b34 100644 --- a/lib/core.js +++ b/lib/core.js @@ -110,12 +110,11 @@ 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._entriesCount++; - if (data.stats.size) { this._fsEntriesTotalBytes += data.stats.size; } @@ -430,8 +429,6 @@ Archiver.prototype._onStatQueueTask = function(task, callback) { task = this._updateQueueTaskWithStats(task, stats); if (task) { - this._entriesCount++; - if (stats.size) { this._fsEntriesTotalBytes += stats.size; }