Skip to content

Commit

Permalink
fix: remove caching of ZipFile
Browse files Browse the repository at this point in the history
closes #801
  • Loading branch information
gotson committed Feb 14, 2022
1 parent c0c7b09 commit 57082bd
Showing 1 changed file with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.gotson.komga.infrastructure.mediacontainer

import com.github.benmanes.caffeine.cache.Caffeine
import mu.KotlinLogging
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator
import org.apache.commons.compress.archivers.ArchiveEntry
Expand All @@ -10,7 +9,6 @@ import org.gotson.komga.domain.model.MediaType
import org.gotson.komga.infrastructure.image.ImageAnalyzer
import org.springframework.stereotype.Service
import java.nio.file.Path
import java.util.concurrent.TimeUnit

private val logger = KotlinLogging.logger {}

Expand All @@ -20,12 +18,6 @@ class ZipExtractor(
private val imageAnalyzer: ImageAnalyzer,
) : MediaContainerExtractor {

private val cache = Caffeine.newBuilder()
.maximumSize(20)
.expireAfterAccess(1, TimeUnit.MINUTES)
.evictionListener { _: Path?, zip: ZipFile?, _ -> zip?.close() }
.build<Path, ZipFile>()

private val natSortComparator: Comparator<String> = CaseInsensitiveSimpleNaturalComparator.getInstance()

override fun mediaTypes(): List<String> = listOf(MediaType.ZIP.value)
Expand Down Expand Up @@ -53,8 +45,8 @@ class ZipExtractor(
.sortedWith(compareBy(natSortComparator) { it.name })
}

override fun getEntryStream(path: Path, entryName: String): ByteArray {
val zip = cache.get(path) { ZipFile(path.toFile()) }!!
return zip.getInputStream(zip.getEntry(entryName)).use { it.readBytes() }
}
override fun getEntryStream(path: Path, entryName: String): ByteArray =
ZipFile(path.toFile()).use { zip ->
zip.getInputStream(zip.getEntry(entryName)).use { it.readBytes() }
}
}

0 comments on commit 57082bd

Please sign in to comment.