From 0ea511756361a35abbf670142d02902fb8198af0 Mon Sep 17 00:00:00 2001 From: liujingxing <18268800083ljx@gmail.com> Date: Wed, 19 Jul 2023 15:57:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=81=A2=E5=A4=8DtoDownloadAwait=E7=B3=BB?= =?UTF-8?q?=E5=88=97=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BD=86=E5=A6=82=E8=A6=81?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E4=B8=8B=E8=BD=BD=E8=BF=9B=E5=BA=A6=EF=BC=8C?= =?UTF-8?q?=E8=AF=B7=E4=BD=BF=E7=94=A8Flow=E6=9B=BF=E4=BB=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rxhttp/src/main/java/rxhttp/CallFactoryExt.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) 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)