diff --git a/rxhttp/src/main/java/rxhttp/CallFactoryExt.kt b/rxhttp/src/main/java/rxhttp/CallFactoryExt.kt index dcda50b3..46b2b076 100644 --- a/rxhttp/src/main/java/rxhttp/CallFactoryExt.kt +++ b/rxhttp/src/main/java/rxhttp/CallFactoryExt.kt @@ -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 @@ -27,6 +28,26 @@ fun CallFactory.toAwaitString(): CallAwait = toAwait() inline fun CallFactory.toAwaitList(): CallAwait> = toAwait() +fun CallFactory.toDownloadAwait( + destPath: String, + append: Boolean = false, +): Await = toDownloadAwait(FileOutputStreamFactory(destPath), append) + +fun CallFactory.toDownloadAwait( + context: Context, + uri: Uri, + append: Boolean = false, +): Await = toDownloadAwait(UriOutputStreamFactory(context, uri), append) + +fun CallFactory.toDownloadAwait( + osFactory: OutputStreamFactory, + append: Boolean = false, +): Await { + if (append && this is ITag) { + tag(OutputStreamFactory::class.java, osFactory) + } + return toAwait(StreamParser(osFactory)) +} fun CallFactory.toFlow(parser: Parser): CallFlow = CallFlow(this, parser)