Skip to content

Commit

Permalink
恢复toDownloadAwait系列方法,但如要监听下载进度,请使用Flow替代
Browse files Browse the repository at this point in the history
  • Loading branch information
liujingxing committed Jul 19, 2023
1 parent 4d502f3 commit 0ea5117
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions rxhttp/src/main/java/rxhttp/CallFactoryExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import rxhttp.wrapper.ITag
import rxhttp.wrapper.callback.FileOutputStreamFactory
import rxhttp.wrapper.callback.OutputStreamFactory
import rxhttp.wrapper.callback.UriOutputStreamFactory
import rxhttp.wrapper.coroutines.Await
import rxhttp.wrapper.coroutines.CallAwait
import rxhttp.wrapper.coroutines.CallFlow
import rxhttp.wrapper.parse.Parser
Expand All @@ -27,6 +28,26 @@ fun CallFactory.toAwaitString(): CallAwait<String> = toAwait()

inline fun <reified T> CallFactory.toAwaitList(): CallAwait<MutableList<T>> = toAwait()

fun CallFactory.toDownloadAwait(
destPath: String,
append: Boolean = false,
): Await<String> = toDownloadAwait(FileOutputStreamFactory(destPath), append)

fun CallFactory.toDownloadAwait(
context: Context,
uri: Uri,
append: Boolean = false,
): Await<Uri> = toDownloadAwait(UriOutputStreamFactory(context, uri), append)

fun <T> CallFactory.toDownloadAwait(
osFactory: OutputStreamFactory<T>,
append: Boolean = false,
): Await<T> {
if (append && this is ITag) {
tag(OutputStreamFactory::class.java, osFactory)
}
return toAwait(StreamParser(osFactory))
}


fun <T> CallFactory.toFlow(parser: Parser<T>): CallFlow<T> = CallFlow(this, parser)
Expand Down

0 comments on commit 0ea5117

Please sign in to comment.