Added appending installers to modules

This commit is contained in:
Viktor De Pasquale
2019-07-11 18:44:05 +02:00
committed by John Wu
parent 967bdeae7b
commit 0785945635
5 changed files with 95 additions and 9 deletions
@@ -10,16 +10,30 @@ inline fun ResponseBody.writeToCachedFile(
context: Context,
fileName: String,
progress: (Long) -> Unit = {}
): File {
val file = File(context.cacheDir, fileName)
withStreams(byteStream(), file.outputStream()) { inStream, outStream ->
): File = byteStream().writeToCachedFile(context, fileName, progress)
inline fun InputStream.writeToCachedFile(
context: Context,
fileName: String,
progress: (Long) -> Unit = {}
) = context.cachedFile(fileName).apply {
writeToFile(this, progress)
}
inline fun InputStream.writeToFile(file: File, progress: (Long) -> Unit = {}) = file.apply {
writeTo(file.outputStream(), progress)
}
inline fun InputStream.writeTo(output: OutputStream, progress: (Long) -> Unit = {}) {
withStreams(this, output) { inStream, outStream ->
inStream.copyToWithProgress(outStream, progress)
}
return file
}
fun ResponseBody.writeToString() = string()
fun Context.cachedFile(name: String) = File(cacheDir, name)
inline fun InputStream.copyToWithProgress(
out: OutputStream,
progressEmitter: (Long) -> Unit,