diff --git a/lib/cli/etcher.js b/lib/cli/etcher.js index 511592b3..2acf45a6 100644 --- a/lib/cli/etcher.js +++ b/lib/cli/etcher.js @@ -87,7 +87,7 @@ permissions.isElevated().then((elevated) => { */ const onProgress = (state) => { state.message = state.active > 1 - ? `${bytes(state.totalSpeed)}/s total, ${bytes(state.speed)}/s avg` + ? `${bytes(state.totalSpeed)}/s total, ${bytes(state.speed)}/s x ${state.active}` : `${bytes(state.totalSpeed)}/s` state.message = `${state.type === 'write' ? 'Flashing' : 'Validating'}: ${state.message}` diff --git a/lib/sdk/image-stream/handlers.js b/lib/sdk/image-stream/handlers.js index 34266afd..75f2d690 100644 --- a/lib/sdk/image-stream/handlers.js +++ b/lib/sdk/image-stream/handlers.js @@ -41,11 +41,11 @@ const errors = require('../../shared/errors') const DEFAULT_EXT = 'img' /** - * @summary Default read-stream highWaterMark value (4M) + * @summary Default read-stream highWaterMark value (1M) * @type {Number} * @constant */ -const STREAM_HWM = 4194304 +const STREAM_HWM = 1048576 /** * @summary Image handlers diff --git a/lib/sdk/writer/index.js b/lib/sdk/writer/index.js index 096445fb..74d573de 100644 --- a/lib/sdk/writer/index.js +++ b/lib/sdk/writer/index.js @@ -375,6 +375,46 @@ class ImageWriter extends EventEmitter { return this } + /** + * @summary Internal progress state handler + * @param {Object} state - progress state + * @example + * pipeline.on('progress', (state) => { + * // ... + * this._onProgress(state) + * }) + */ + _onProgress (state) { + state.totalSpeed = 0 + state.active = 0 + + state.flashing = 0 + state.verifying = 0 + state.failed = 0 + state.succeeded = 0 + + this.destinations.forEach((dest) => { + state.flashing += !dest.error && !dest.finished ? 1 : 0 + state.verifying += !dest.error && !dest.verified ? 1 : 0 + state.failed += dest.error ? 1 : 0 + if (!(dest.finished && dest.verified) && !dest.error) { + state.totalSpeed += state.type === 'write' + ? dest.stream.speed + : dest.progress.state.speed + state.active += 1 + } + }) + + state.speed = state.active + ? state.totalSpeed / state.active + : state.active + + state.succeeded = state.active - state.failed - state.flashing - state.verifying + state.eta = state.speed ? state.remaining / state.speed : 0 + + this.emit('progress', state) + } + /** * @summary Start the writing process * @returns {ImageWriter} imageWriter @@ -438,18 +478,7 @@ class ImageWriter extends EventEmitter { progressStream.on('progress', (state) => { state.type = 'check' - state.totalSpeed = 0 - state.active = 0 - this.destinations.forEach((destination) => { - if (!destination.verified && !destination.error) { - state.totalSpeed += destination.progress.state.speed - state.active += 1 - } - }) - state.speed = state.active - ? state.totalSpeed / state.active - : state.active - this.emit('progress', state) + this._onProgress(state) }) this.destinations.forEach((destination) => { @@ -681,18 +710,7 @@ class ImageWriter extends EventEmitter { // Pipeline.bind(progressStream, 'progress'); progressStream.on('progress', (state) => { state.type = 'write' - state.totalSpeed = 0 - state.active = 0 - this.destinations.forEach((destination) => { - if (!destination.finished && !destination.error) { - state.totalSpeed += destination.stream.speed - state.active += 1 - } - }) - state.speed = state.active - ? state.totalSpeed / state.active - : state.active - this.emit('progress', state) + this._onProgress(state) }) pipeline.bind(this.source.stream, 'error')