diff --git a/lib/core.js b/lib/core.js index b04010fd8..84632d99f 100644 --- a/lib/core.js +++ b/lib/core.js @@ -44,11 +44,11 @@ var Archiver = function(format, options) { Transform.call(this, options); - this._entries = []; this._format = false; this._module = false; this._pending = 0; this._pointer = 0; + this._totalBytes = 0 this._queue = async.queue(this._onQueueTask.bind(this), 1); this._queue.drain = this._onQueueDrain.bind(this); @@ -190,7 +190,11 @@ Archiver.prototype._moduleAppend = function(source, data, callback) { * @type {EntryData} */ this.emit('entry', data); - this._entries.push(data); + + var size = data.stats ? data.stats.size : data.size || 0 + + this._totalBytes += size + this.emit('progress', {total: this._totalBytes, size: size}) setImmediate(callback); }.bind(this)); diff --git a/test/archiver.js b/test/archiver.js index 4f6a989c2..1e20c664c 100644 --- a/test/archiver.js +++ b/test/archiver.js @@ -66,6 +66,11 @@ describe('archiver', function() { archive.pipe(testStream); + archive.on('progress', function(progress) { + assert.property(progress, 'total') + assert.property(progress, 'size') + }) + archive .append(testBuffer, { name: 'buffer.txt', date: testDate }) .append(fs.createReadStream('test/fixtures/test.txt'), { name: 'stream.txt', date: testDate })