https://github.com/underthestars-zhy/asyncurlsession
A replacement of Apple's URLSession
https://github.com/underthestars-zhy/asyncurlsession
async-await ios swift
Last synced: 2 months ago
JSON representation
A replacement of Apple's URLSession
- Host: GitHub
- URL: https://github.com/underthestars-zhy/asyncurlsession
- Owner: underthestars-zhy
- Created: 2022-04-03T15:02:20.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-28T08:25:01.000Z (almost 3 years ago)
- Last Synced: 2024-12-30T21:35:53.443Z (4 months ago)
- Topics: async-await, ios, swift
- Language: Swift
- Homepage:
- Size: 6.84 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AsyncURLSession
Apple brought us a very shiny feature `async`. And `URLSession` supported it at once. But you can't use `downloadTask` with async. So this package can help you deal with this kind of problem.
## Without Progress
```swift
let (url, response) = try await AsyncURLSession.shared.url(from: .init(string: "https://filesamples.com/samples/document/txt/sample1.txt")!)
```In this case `AsyncURLSession` will provide you a system url which is the downloaded file path.
## With Progress
```swift
let (progress, response) = try await AsyncURLSession.shared.download(from: .init(string: "https://filesamples.com/samples/document/txt/sample1.txt")!, location: url)
let all = response.expectedContentLengthfor try await current in progress {
let progress = Double(current) / Double(all)print(Int(progress * 100), "%")
}
```In this case, you need to provide a url where you file will be donwloaded to.
## Others
1. Both support `URL` and `URLRequest`
2. You can create your custom `AsyncURLSession`
3. Can use on `Linux` (not be tested, but I suppose to)