Skip to content

Commit

Permalink
feat: 実際にダウンロードしたファイルと実際のファイルのサイズをチェックするようにした。
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Jun 26, 2023
1 parent 5b0d082 commit a91a4e6
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,14 @@ class ImageCacheRepositoryImpl @Inject constructor(
private suspend fun downloadAndSaveFile(url: String, file: File) {
file.outputStream().use { out ->
val req = Request.Builder().url(url).build()
okHttpClientProvider.get().newCall(req).execute().body?.byteStream()
val response = okHttpClientProvider.get().newCall(req).execute()
val contentLength = response.header("Content-Length")?.toLongOrNull()
response.body?.byteStream()
?.use { inStream ->
inStream.copyTo(out)
val bytesCopied = inStream.copyTo(out)
if (contentLength != null && bytesCopied != contentLength) {
throw Exception("Download failed: url=$url")
}
}
val options = BitmapFactory.Options()
options.inJustDecodeBounds = true
Expand Down

0 comments on commit a91a4e6

Please sign in to comment.