mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-24 07:17:18 +00:00
feat(writer): Display actual write speed (#1863)
As we've actually been displaying the read-speed in various forms during the flashing process, this is a venture into displaying the actual write-speed from the end of the pipeline. Change-Type: minor Changelog-Entry: Display actual write speed
This commit is contained in:
parent
8e79e9e459
commit
4e891151f4
@ -18,9 +18,11 @@
|
||||
|
||||
const stream = require('readable-stream')
|
||||
const fs = require('fs')
|
||||
const speedometer = require('speedometer')
|
||||
const debug = require('debug')('block-write-stream')
|
||||
|
||||
const CHUNK_SIZE = 64 * 1024
|
||||
const UPDATE_INTERVAL_MS = 500
|
||||
|
||||
/**
|
||||
* @summary BlockWriteStream
|
||||
@ -60,6 +62,23 @@ class BlockWriteStream extends stream.Writable {
|
||||
this.blocksRead = 0
|
||||
this.bytesWritten = 0
|
||||
this.blocksWritten = 0
|
||||
this.meter = speedometer()
|
||||
this.delta = 0
|
||||
this.speed = 0
|
||||
|
||||
this.clear = () => {
|
||||
clearInterval(this.timer)
|
||||
}
|
||||
|
||||
this.update = () => {
|
||||
this.speed = this.meter(this.delta)
|
||||
this.delta = 0
|
||||
}
|
||||
|
||||
this.once('end', this.clear)
|
||||
this.once('error', this.clear)
|
||||
|
||||
this.timer = setInterval(this.update, UPDATE_INTERVAL_MS)
|
||||
|
||||
this.closed = false
|
||||
this.destroyed = false
|
||||
@ -116,6 +135,7 @@ class BlockWriteStream extends stream.Writable {
|
||||
|
||||
fs.write(this.fd, chunk, 0, chunk.length, chunk.position, (error, bytesWritten) => {
|
||||
this.bytesWritten += bytesWritten
|
||||
this.delta += bytesWritten
|
||||
this.blocksWritten += 1
|
||||
this.position += bytesWritten
|
||||
next(error)
|
||||
|
@ -226,6 +226,7 @@ class ImageWriter extends EventEmitter {
|
||||
progressStream.on('progress', (state) => {
|
||||
state.device = options.path
|
||||
state.type = 'write'
|
||||
state.speed = target.speed
|
||||
this.emit('progress', state)
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user