Simple, reactive and functional downloader for iOS Swift with the power of RxSwift
, RxAlamofire
To run the example project, clone the repo, and run pod install
from the Example directory first.
PhDownloader is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'PhDownloader'
Petrus Nguyễn Thái Học, [email protected]
let downloader: PhDownloader = PhDownloaderFactory.makeDownloader(
with: .init(
maxConcurrent: 2,
throttleProgress: .milliseconds(500)
)
)
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)
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)
let 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)
PhDownloader is available under the MIT license. See the LICENSE file for more info.