oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1import Foundation
2
3/// Request-local progress survives the lifetime and credential-renewal wrappers.
4final class UploadProgress: Sendable, Equatable {
5 let report: @Sendable (Double) -> Void
6 init(_ report: @escaping @Sendable (Double) -> Void) { self.report = report }
7 static func == (lhs: UploadProgress, rhs: UploadProgress) -> Bool { lhs === rhs }
8}
9
10final class UploadDelegate: NSObject, URLSessionTaskDelegate, Sendable {
11 let progress: UploadProgress
12 init(_ progress: UploadProgress) { self.progress = progress }
13 func urlSession(_ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) {
14 if totalBytesExpectedToSend > 0 { progress.report(min(1, Double(totalBytesSent) / Double(totalBytesExpectedToSend))) }
15 }
16 func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest) async -> URLRequest? { nil }
17}
18