Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Sources/Hub/Downloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
// See LICENSE at https://github.com/huggingface/swift-coreml-diffusers/LICENSE
//

import Combine
import Foundation

/// A robust file downloader with support for resumable downloads and progress reporting.
///
/// The Downloader class handles file downloads from remote URLs with features including
/// automatic resume capability, progress tracking, speed monitoring, and retry mechanisms.
/// It supports both foreground and background download sessions for different use cases.
final class Downloader: NSObject, Sendable, ObservableObject {
final class Downloader: NSObject, Sendable {
private let destination: URL
private let incompleteDestination: URL
private let downloadResumeState: DownloadResumeState = .init()
Expand Down
7 changes: 4 additions & 3 deletions Sources/Hub/HubApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,10 @@ public extension HubApi {
}
}

/// Note we go from Combine in Downloader to callback-based progress reporting
/// We'll probably need to support Combine as well to play well with Swift UI
/// (See for example PipelineLoader in swift-coreml-diffusers)
/// Downloads the file with progress tracking.
/// - Parameter progressHandler: Called with download progress (0.0-1.0) and speed in bytes/sec, if available.
/// - Returns: Local file URL (uses cached file if commit hash matches).
/// - Throws: ``EnvironmentError`` errors for file and metadata validation failures, ``Downloader.DownloadError`` errors during transfer, or ``CancellationError`` if the task is cancelled.
@discardableResult
func download(progressHandler: @escaping (Double, Double?) -> Void) async throws -> URL {
let localMetadata = try hub.readDownloadMetadata(metadataPath: metadataDestination)
Expand Down
1 change: 0 additions & 1 deletion Tests/HubTests/DownloaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Arda Atahan Ibis on 1/28/25.
//

import Combine
import XCTest

@testable import Hub
Expand Down