项目作者: cornerAnt

项目描述 :
Digger is a lightweight download framework that requires only one line of code to complete the file download task
高级语言: Swift
项目地址: git://github.com/cornerAnt/Digger.git
创建时间: 2017-11-01T12:54:27Z
项目社区:https://github.com/cornerAnt/Digger

开源协议:MIT License

下载




Version
Carthage compatible
Version

中文说明

Digger is a lightweight download framework that requires only one line of code to complete the file download task.

Based on URLSession, pure Swift language implementation, support chain syntax call, real-time download progress, real-time download speed, breakpoint download.

The user forces the app to be shut down, for example by sliding off the app.
Digger can still resume downloading tasks.



Features:

  • Large file download
  • Multi thread Download
  • Thread safety
  • Breakpoint downloading
  • Controllable concurrency

Requirements”

  • iOS 8.0+
  • Xcode 9.0+
  • Swift 4.0+

    Installation

CocoaPods

Add to your Podfile:

  1. pod 'Digger'

Carthage

Add to your Cartfile:

  1. github "cornerAnt/Digger"

Usage

Basic:

Download a file in the Digger directory under the sandbox’s Caches

  1. let url = "http://example.com/digger.mp4"
  2. Digger.download(url)

Choose different callbacks depending on your needs

  1. Digger.download(url)
  2. .progress(nil)
  3. .speed(nil)
  4. .completion(nil)
  1. let url = "http://example.com/digger.mp4"
  2. Digger.download(url)
  3. .progress({ (progresss) in
  4. print(progresss.fractionCompleted)
  5. })
  6. .speed({ (speed) in
  7. print(speed)
  8. })
  9. .completion { (result) in
  10. switch result {
  11. case .success(let url):
  12. print(url)
  13. case .failure(let error):
  14. print(error)
  15. }
  16. }
  17. }

Config yourself

  1. /// Start the task at once,default is true
  2. DiggerManager.shared.startDownloadImmediately = false
  3. /// maxConcurrentTasksCount,deault is 3
  4. DiggerManager.shared.maxConcurrentTasksCount = 4
  5. /// request timeout,deault is 100
  6. DiggerManager.shared.timeout = 150
  7. /// allowsCellularAccess,deault is true
  8. DiggerManager.shared.allowsCellularAccess = false
  9. /// loglevel,deault is high
  10. /*
  11. ***************DiggerLog****************
  12. file : ExampleController.swift
  13. method : viewDidLoad()
  14. line : [31]:
  15. info : digger log
  16. */
  17. // If you want to close,set the level to be .none
  18. DiggerManager.shared.logLevel = .none
  19. // MARK:- DiggerCache
  20. /// In the sandbox cactes directory, custom your cache directory
  21. DiggerCache.cachesDirectory = "Directory"
  22. /// Delete all downloaded files
  23. DiggerCache.cleanDownloadFiles()
  24. /// Delete all temporary download files
  25. DiggerCache.cleanDownloadTempFiles()
  26. /// Get the system's available memory size
  27. _ = DiggerCache.systemFreeSize()
  28. /// Get the size of the downloaded file
  29. _ = DiggerCache.downloadedFilesSize()
  30. /// Get the path to all downloaded files
  31. _ = DiggerCache.pathsOfDownloadedfiles
  32. }

Contributing

  1. Fork
  2. Commit changes to a branch in your fork
  3. Push your code and make a pull request

License

Digger is Copyright (c) 2017 cornerAnt and released as open source under the attached MIT License.