Skip to content

Commit

Permalink
다운 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
JuTaK97 committed Jul 8, 2023
1 parent 497065e commit f1f6380
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions app/src/main/java/com/wafflestudio/snutt2/views/RNViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,23 @@ class RNViewModel @Inject constructor(

init {
viewModelScope.launch(Dispatchers.IO) {
val urlConnection = URL("https://snutt-rn-assets.s3.ap-northeast-2.amazonaws.com/android.jsbundle").openConnection() as HttpURLConnection
urlConnection.connect()
val inputStream = urlConnection.inputStream
val outputFile = File(application.applicationContext.cacheDir, "android.jsbundle")
val bundleFile = File(application.applicationContext.cacheDir, "android.jsbundle")
if (bundleFile.canRead().not()) {
val urlConnection = URL("https://snutt-rn-assets.s3.ap-northeast-2.amazonaws.com/android.jsbundle").openConnection() as HttpURLConnection
urlConnection.connect()
val inputStream = urlConnection.inputStream

val outputStream = FileOutputStream(outputFile)
val buffer = ByteArray(1024000)
var bytesRead: Int
val outputStream = FileOutputStream(bundleFile)
val buffer = ByteArray(1024000)
var bytesRead: Int

while (inputStream.read(buffer).also { bytesRead = it } != -1) {
outputStream.write(buffer, 0, bytesRead)
while (inputStream.read(buffer).also { bytesRead = it } != -1) {
outputStream.write(buffer, 0, bytesRead)
}
outputStream.close()
inputStream.close()
urlConnection.disconnect()
}
outputStream.close()
inputStream.close()
urlConnection.disconnect()
_done.postValue(true)
}
}
Expand Down

0 comments on commit f1f6380

Please sign in to comment.