Files
tart/Sources/tart/Logging/URLSessionLogger.swift
T
Fedor Korotkov 49d430b3c4 Update dependencies and styles (#12)
* Update deps and .editorconfig

* run config
2022-03-24 18:54:49 +03:00

18 lines
573 B
Swift

import Foundation
public class URLSessionLogger: NSObject, URLSessionTaskDelegate {
let renderer: Logger
public init(_ renderer: Logger) {
self.renderer = renderer
}
public func urlSession(_ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) {
renderer.updateLastLine(URLSessionLogger.lineToRender(task.progress))
}
private static func lineToRender(_ progress: Progress) -> String {
String(100 * progress.completedUnitCount / progress.totalUnitCount) + "%"
}
}