fix closable resource usage

This commit is contained in:
Chloe committed 2026-02-01 16:37:59 -07:00
1 parent 0d01f8c74b
commit 2754cc4bb8
2 files changed
+8 -6

No files matched your search

@@ -147,14 +147,16 @@ class ReleaseManager private constructor(
_uiState.value = ReleaseManagerState.InDownload(0, download.size) _uiState.value = ReleaseManagerState.InDownload(0, download.size)
try { try {
val fileStream = DownloadUtils.downloadStream( DownloadUtils.downloadStream(
httpClient, httpClient,
download.url download.url
) { progress, outOf -> ) { progress, outOf ->
_uiState.value = ReleaseManagerState.InDownload(progress, outOf) _uiState.value = ReleaseManagerState.InDownload(progress, outOf)
}.use { fileStream ->
outputFile.outputStream().use {
fileStream.copyTo(it)
}
} }
fileStream.copyTo(outputFile.outputStream())
} catch (e: Exception) { } catch (e: Exception) {
sendError(e) sendError(e)
return return
@@ -58,9 +58,9 @@ object DownloadUtils {
val progressClient = progressClientBuilder.build() val progressClient = progressClientBuilder.build()
val call = progressClient.newCall(request) val call = progressClient.newCall(request)
return call.executeAsync().use { response -> val response = call.executeAsync()
response.body.byteStream()
} return response.body.byteStream()
} }
suspend fun extractFileFromZipStream(inputStream: InputStream, outputStream: OutputStream, zipPath: String) { suspend fun extractFileFromZipStream(inputStream: InputStream, outputStream: OutputStream, zipPath: String) {