mirror of
https://github.com/gotson/komga.git
synced 2025-12-20 07:23:34 +01:00
parent
c0c7b09faa
commit
57082bd990
1 changed files with 4 additions and 12 deletions
|
|
@ -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
|
||||
|
|
@ -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 {}
|
||||
|
||||
|
|
@ -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)
|
||||
|
|
@ -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() }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue