aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Library/NetSocket/FileProgress.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Hotline/Library/NetSocket/FileProgress.swift')
-rw-r--r--Hotline/Library/NetSocket/FileProgress.swift15
1 files changed, 14 insertions, 1 deletions
diff --git a/Hotline/Library/NetSocket/FileProgress.swift b/Hotline/Library/NetSocket/FileProgress.swift
index c2306f3..2064c59 100644
--- a/Hotline/Library/NetSocket/FileProgress.swift
+++ b/Hotline/Library/NetSocket/FileProgress.swift
@@ -12,14 +12,27 @@ public extension NetSocket {
public let sent: Int
/// Total file size (may be nil if unknown)
public let total: Int?
+ /// Size of most recent packet
+ public let now: Int
+ /// Total progress so far (0.0 to 1.0)
+ public let progress: Double
/// Smoothed transfer rate in bytes per second (EMA), if enough samples collected
public let bytesPerSecond: Double?
/// Estimated time remaining (seconds) based on smoothed rate, if available
public let estimatedTimeRemaining: TimeInterval?
- public init(sent: Int, total: Int?, bytesPerSecond: Double? = nil, estimatedTimeRemaining: TimeInterval? = nil) {
+ public init(sent: Int, total: Int?, now: Int = 0, bytesPerSecond: Double? = nil, estimatedTimeRemaining: TimeInterval? = nil) {
self.sent = sent
self.total = total
+ self.now = now
+
+ if let t = total {
+ self.progress = max(0.0, min(1.0, Double(sent) / Double(t)))
+ }
+ else {
+ self.progress = 0.0
+ }
+
self.bytesPerSecond = bytesPerSecond
self.estimatedTimeRemaining = estimatedTimeRemaining
}