https://github.com/appunite/cedric
Single / multiple files downloader written in pure Swift
https://github.com/appunite/cedric
downloader file ios parallel serial urlsession
Last synced: 7 months ago
JSON representation
Single / multiple files downloader written in pure Swift
- Host: GitHub
- URL: https://github.com/appunite/cedric
- Owner: appunite
- License: mit
- Created: 2018-05-06T17:05:34.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-05-04T16:51:11.000Z (almost 2 years ago)
- Last Synced: 2024-11-13T14:03:01.371Z (over 1 year ago)
- Topics: downloader, file, ios, parallel, serial, urlsession
- Language: Swift
- Homepage:
- Size: 3.32 MB
- Stars: 13
- Watchers: 19
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://github.com/Carthage/Carthage)
[](https://cocoapods.org/pods/Cedric)
[](https://cocoapods.org/pods/Cedric)
[](https://travis-ci.org/codecov/example-swift)
[](https://codecov.io/gh/codecov/example-swift/branch/master)
[](https://cocoapods.org/pods/Cedric)
# Cedric
## Who am I?
Hey! My name is **Cedric**, I was born to help iOS / macOS developers with a quite difficult task that is downloading files.
## What are my responsibilities?
Behind just downloading files I'm able to perform operations like:
- notify about updates via **MulticastDelegate**
- perform operations in a **serial** or **parallel (with limit)** options
- perform browser-like download with **always creating new files**
- **reuse** already downloaded files for the same resource
- notify that all resources from queue are downloaded
- apply attributes to files specified in resource
## Example usage
```swift
let resource = DownloadResource(id: asset.id, source: asset.url, destinationName: asset.name + ".mp3", mode: .notDownloadIfExists)
try cedric.enqueueDownload(forResource: resource)
func cedric(_ cedric: Cedric, didFinishDownloadingResource resource: DownloadResource, toFile file: DownloadedFile) {
do {
let url = try file.url()
guard let image = UIImage(contentsOfFile: url.path) else { return }
fileImageView.image = image
} catch let error {
...
}
}
```
## Cedric Configuration Modes
As I've mentioned, I'm able to work in different modes with allowing for serial or parallel downloading.
Using serial mode (downloading files in the queue one by one):
```swift
let configuration = CedricConfiguration(mode: .serial)
return Cedric(configuration: configuration)
```

Using parallel mode (with concurent 3 tasks):
```swift
let configuration = CedricConfiguration(mode: .parallel(max: 3))
return Cedric(configuration: configuration)
```

**Important note**
By default all files are stored in "Downloads" directory, if you want to store them in different directory please pass it's name to `CedricConfiguration` object. The same configuration should be passed if you use `FileManager.cedricPath(...)`
### Carthage
Add the following entry in your Cartfile:
```
github "appunite/Cedric"
```
Then run `carthage update`.
### Cocoapods
Add the following entry in your Podfile
```
pod 'Cedric'
```
Then run `pod install`.
### Contribution
Project is created and maintained by **Szymon Mrozek**.
We could use your help with reporting or fixing bugs. We would also like to hear from you about feature suggestions. If you have an idea how to make Cedric better you are welcome to send us a Pull Request.
### License
Cedric is released under an MIT license. See [License.md](LICENSE.md) for more information.