From 105d3111d71623cb831af3f411ea253db766f369 Mon Sep 17 00:00:00 2001 From: jafar aml Date: Thu, 23 Dec 2021 13:55:27 +0330 Subject: [PATCH] :memo: Update README.md (#825) --- fuel/README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/fuel/README.md b/fuel/README.md index 70e2d6c99..9f0911ce6 100644 --- a/fuel/README.md +++ b/fuel/README.md @@ -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: