Downloader

public class Downloader : NSObject
extension Downloader: URLSessionDownloadDelegate

Downloader: A helper class to download files.

  • Downloads a file asynchronously.

    Usage Example:

    • Download MNIST files:
      let semaphore = DispatchSemaphore(value: 0)
      let downloader = Downloader()
      var localURL: URL?
      downloader.download(
          fileAt: URL(string: "https://storage.googleapis.com/cvdf-datasets/mnist/train-images-idx3-ubyte.gz")!,
          cacheName: "mnist",
          fileName: "train-images.gz"
      ) { url, error in
          guard let url = url else {
              if let error = error { print(error) }
              fatalError("Data not downloaded.")
          }
          localURL = url
          semaphore.signal()
      }
      semaphore.wait()
      // Use the URL here.
    

    Declaration

    Swift

    public func download(fileAt remoteUrl: URL,
                         cacheName: String,
                         fileName: String,
                         completionHandler: @escaping (URL?, Error?) -> Void)
  • Downloads a file synchronously.

    Usage Example:

    • Download MNIST files:
      let localURL = Downloader.download(
          fileAt: URL(string: "https://storage.googleapis.com/cvdf-datasets/mnist/train-images-idx3-ubyte.gz")!,
          cacheName: "mnist",
          fileName: "train-images.gz"
      )
      // Use the URL here.
    

    Declaration

    Swift

    static public func download(fileAt remoteUrl: URL,
                                cacheName: String,
                                fileName: String) -> URL?
  • Undocumented

    Declaration

    Swift

    public func urlSession(_ session: URLSession,
                           downloadTask: URLSessionDownloadTask,
                           didWriteData bytesWritten: Int64,
                           totalBytesWritten: Int64,
                           totalBytesExpectedToWrite: Int64)
  • Undocumented

    Declaration

    Swift

    public func urlSession(_ session: URLSession,
                           downloadTask: URLSessionDownloadTask,
                           didFinishDownloadingTo location: URL)
  • Undocumented

    Declaration

    Swift

    public func urlSession(_ session: URLSession,
                           task: URLSessionTask,
                           didCompleteWithError error: Error?)