Skip to content

Commit

Permalink
Progress tracking improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharee committed Aug 28, 2024
1 parent 3736240 commit a247e7f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,19 @@ object CryptUtils {
enc: Source?,
encSize: Long,
expected: Long,
progressCallback: suspend (current: Long, max: Long, bps: Long) -> Unit
progressCallback: suspend (current: Long, max: Long, bps: Long) -> Unit,
): Boolean {
if (enc == null) {
return false
}

val buffer = ByteArray(DEFAULT_CHUNK_SIZE)
var crcVal = CRC32.initialValue

trackOperationProgress(
size = encSize,
progressCallback = progressCallback,
operation = {
val buffer = ByteArray(DEFAULT_CHUNK_SIZE)
val len = enc.readAtMostTo(buffer, 0, buffer.size)

if (len > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ object Downloader {
model.statusText.value = MR.strings.checkingCRC()
val result = CryptUtils.checkCrc32(
encFile.openInputStream() ?: return,
size,
encFile.getLength(),
crc32,
) { current, max, bps ->
model.progress.value = current to max
Expand All @@ -164,7 +164,7 @@ object Downloader {
Event.Download.Progress(
MR.strings.checkingCRC(),
current,
max
max,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class Averager(initialCapacity: Int = 1000, private val thresholdNanos: Long = 1
}
}

suspend fun close() {
mutex.withLock {
chunk.clear()
}
}

private fun unsafeUpdate(durationNano: Long, read: Long) {
val currentTimeNano = currentTimeNano()
chunk.add(ChunkData(durationNano, read, currentTimeNano))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,6 @@ suspend fun trackOperationProgress(
}

finished.value = true
averager.close()
}
}

0 comments on commit a247e7f

Please sign in to comment.