Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hoc081098/phdownloader
Petrus Hoc's Downloader - Simple, reactive and functional downloader for iOS Swift with the power of RxSwift, RxAlamofire - RxSwift Downloader - RxDownloader
https://github.com/hoc081098/phdownloader
functional-reactive-programming ios ios-rx-downloader rxalamofire rxdownload rxswift swift swift-downloader swift5 swifty-downloader
Last synced: about 2 months ago
JSON representation
Petrus Hoc's Downloader - Simple, reactive and functional downloader for iOS Swift with the power of RxSwift, RxAlamofire - RxSwift Downloader - RxDownloader
- Host: GitHub
- URL: https://github.com/hoc081098/phdownloader
- Owner: hoc081098
- License: mit
- Created: 2020-07-17T14:47:28.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-23T19:34:25.000Z (3 months ago)
- Last Synced: 2024-10-25T22:05:19.999Z (2 months ago)
- Topics: functional-reactive-programming, ios, ios-rx-downloader, rxalamofire, rxdownload, rxswift, swift, swift-downloader, swift5, swifty-downloader
- Language: Swift
- Homepage: https://cocoapods.org/pods/PhDownloader
- Size: 93.8 KB
- Stars: 9
- Watchers: 1
- Forks: 2
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# PhDownloader (Petrus Hoc's Downloader)
Simple, reactive and functional downloader for iOS Swift with the power of `RxSwift`, `RxAlamofire`.
RxSwift Downloader.
RxDownloader.[![iOS Build CI](https://github.com/hoc081098/PhDownloader/actions/workflows/ios-build.yml/badge.svg)](https://github.com/hoc081098/PhDownloader/actions/workflows/ios-build.yml)
[![Version](https://img.shields.io/cocoapods/v/PhDownloader.svg?style=flat)](https://cocoapods.org/pods/PhDownloader)
[![License](https://img.shields.io/cocoapods/l/PhDownloader.svg?style=flat)](https://cocoapods.org/pods/PhDownloader)
[![Platform](https://img.shields.io/cocoapods/p/PhDownloader.svg?style=flat)](https://cocoapods.org/pods/PhDownloader)
[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fhoc081098%2FPhDownloader&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com)## Example
To run the example project, clone the repo, and run `pod install` from the Example directory first.
## Requirements
## Installation
PhDownloader is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'PhDownloader'
```## Author
Petrus Nguyễn Thái Học, [email protected]
## Usagement
### Create downloader
```swift
let downloader: PhDownloader = PhDownloaderFactory.makeDownloader(
with: .init(
maxConcurrent: 2,
throttleProgress: .milliseconds(500)
)
)
```### Obseve download result (for showing snackbar, toast, alert, ...)
```swift
downloader
.downloadResult$
.subscribe(onNext: { result in
switch result {
case .success(let request):
...
case .failure(let request, let error):
...
case .cancelled(let request):
...
}
})
.disposed(by: disposeBag)
```### Obseve download state (for updating UI)
```swift
downloader
.observe(by: ["id1", "id2", "id3"])
.subscribe(onNext: { tasks in
...
})
.disposed(by: disposeBag)downloader
.observe(by: "Request id")
.subscribe(onNext: { task in
...
})
.disposed(by: disposeBag)
```### Enqueue, cancel, cancelAll, remove:
```swiftlet id = "Request id"
downloader
.enqueue(
.init(
identifier: id,
url: URL(string: "https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_1920_18MG.mp4")!,
fileName: "test_file_\(id).mp4",
savedDir: FileManager.default
.urls(for: .documentDirectory, in: .userDomainMask)
.first!
.appendingPathComponent("downloads", isDirectory: true)
)
)
.subscribe()
.disposed(by: disposeBag)downloader
.cancel(by: id)
.subscribe()
.disposed(by: disposeBag)downloader
.cancelAll()
.subscribe()
.disposed(by: disposeBag)
downloader
.remove(identifier: id)
.subscribe()
.disposed(by: disposeBag)
```## License
PhDownloader is available under the MIT license. See the LICENSE file for more info.