ProgressDownloader.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import Foundation
  2. /// Bridges URLSessionDownloadDelegate progress callbacks to Swift concurrency.
  3. /// Each instance manages a single download with real-time progress reporting.
  4. ///
  5. /// This is a stub for test-first development. The implementation will be
  6. /// filled in by the fix-download-progress task.
  7. final class ProgressDownloader: NSObject, URLSessionDownloadDelegate, Sendable {
  8. /// Result of a completed download.
  9. struct Result: Sendable {
  10. let fileURL: URL
  11. let response: HTTPURLResponse
  12. }
  13. /// Download a file with progress reporting.
  14. ///
  15. /// - Parameters:
  16. /// - request: The URLRequest to download.
  17. /// - sessionConfiguration: URLSession configuration (injectable for testing).
  18. /// - onProgress: Called on each progress update (0.0-1.0). Called on arbitrary thread.
  19. /// - Returns: The temporary file URL and HTTP response.
  20. static func download(
  21. request: URLRequest,
  22. sessionConfiguration: URLSessionConfiguration = .default,
  23. onProgress: @escaping @Sendable (Double) -> Void
  24. ) async throws -> Result {
  25. // STUB: To be implemented by fix-download-progress task.
  26. // This stub exists so that tests compile in the write-tests phase.
  27. fatalError("ProgressDownloader.download not yet implemented")
  28. }
  29. // MARK: - URLSessionDownloadDelegate (stubs)
  30. func urlSession(
  31. _ session: URLSession,
  32. downloadTask: URLSessionDownloadTask,
  33. didFinishDownloadingTo location: URL
  34. ) {
  35. fatalError("Not yet implemented")
  36. }
  37. func urlSession(
  38. _ session: URLSession,
  39. downloadTask: URLSessionDownloadTask,
  40. didWriteData bytesWritten: Int64,
  41. totalBytesWritten: Int64,
  42. totalBytesExpectedToWrite: Int64
  43. ) {
  44. fatalError("Not yet implemented")
  45. }
  46. func urlSession(
  47. _ session: URLSession,
  48. task: URLSessionTask,
  49. didCompleteWithError error: (any Error)?
  50. ) {
  51. fatalError("Not yet implemented")
  52. }
  53. }