Skip to content

Commit

Permalink
📝 Update README.md (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
jafar-aml authored Dec 23, 2021
1 parent 0b71fe1 commit 105d311
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions fuel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,32 @@ The `stream` variant expects your callback to provide a `Pair` with both the `Ou
- use an `EmptyDeserializer` with `await(deserializer)` or one of the `response(deserializer)` variants
- provide an `InputStream` callback that `throws` or returns an empty `InputStream`.

For downloading larger files it is good to use `request.streamDestination { }` instead of `request.fileDestination { }`

```kotlin
val outputStream = FileOutputStream(File(filePath))

Fuel.download("https://httpbin.org/bytes/32768")
.streamDestination { response, request -> Pair(outputStream, { request.body.toStream() }) }
.progress { readBytes, totalBytes ->
val progress = readBytes.toFloat() / totalBytes.toFloat() * 100
println("Bytes downloaded $readBytes / $totalBytes ($progress %)")
}
.response { result ->

result.fold(

success = {

},

failure = {

}
)
}
```

### Cancel an async `Request`

The `response` functions called with a `handler` are async and return a `CancellableRequest`. These requests expose a few extra functions that can be used to control the `Future` that should resolve a response:
Expand Down

0 comments on commit 105d311

Please sign in to comment.