mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 11:24:35 -05:00
use commons-compress everywhere (#570)
This commit is contained in:
@@ -18,7 +18,6 @@ import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.jetbrains.exposed.sql.update
|
||||
import suwayomi.tachidesk.manga.impl.CategoryManga.removeMangaFromCategory
|
||||
import suwayomi.tachidesk.manga.model.dataclass.CategoryDataClass
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryMangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryMetaTable
|
||||
|
||||
@@ -3,21 +3,21 @@ package suwayomi.tachidesk.manga.impl.download
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
|
||||
import org.apache.commons.compress.archivers.zip.ZipFile
|
||||
import suwayomi.tachidesk.manga.impl.download.model.DownloadChapter
|
||||
import suwayomi.tachidesk.manga.impl.util.getChapterCbzPath
|
||||
import suwayomi.tachidesk.manga.impl.util.getChapterDownloadPath
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipFile
|
||||
import java.util.zip.ZipInputStream
|
||||
import java.util.zip.ZipOutputStream
|
||||
|
||||
class ArchiveProvider(mangaId: Int, chapterId: Int) : DownloadedFilesProvider(mangaId, chapterId) {
|
||||
override fun getImage(index: Int): Pair<InputStream, String> {
|
||||
val cbzPath = getChapterCbzPath(mangaId, chapterId)
|
||||
val zipFile = ZipFile(cbzPath)
|
||||
val zipEntry = zipFile.entries().toList().sortedWith(compareBy({ it.name }, { it.name }))[index]
|
||||
val zipEntry = zipFile.entries.toList().sortedWith(compareBy({ it.name }, { it.name }))[index]
|
||||
val inputStream = zipFile.getInputStream(zipEntry)
|
||||
val fileType = zipEntry.name.substringAfterLast(".")
|
||||
return Pair(inputStream.buffered(), "image/$fileType")
|
||||
@@ -39,17 +39,17 @@ class ArchiveProvider(mangaId: Int, chapterId: Int) : DownloadedFilesProvider(ma
|
||||
outputFile.createNewFile()
|
||||
}
|
||||
|
||||
ZipOutputStream(outputFile.outputStream()).use { zipOut ->
|
||||
ZipArchiveOutputStream(outputFile.outputStream()).use { zipOut ->
|
||||
if (chapterFolder.isDirectory) {
|
||||
chapterFolder.listFiles()?.sortedBy { it.name }?.forEach {
|
||||
val entry = ZipEntry(it.name)
|
||||
val entry = ZipArchiveEntry(it.name)
|
||||
try {
|
||||
zipOut.putNextEntry(entry)
|
||||
zipOut.putArchiveEntry(entry)
|
||||
it.inputStream().use { inputStream ->
|
||||
inputStream.copyTo(zipOut)
|
||||
}
|
||||
} finally {
|
||||
zipOut.closeEntry()
|
||||
zipOut.closeArchiveEntry()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ class ArchiveProvider(mangaId: Int, chapterId: Int) : DownloadedFilesProvider(ma
|
||||
|
||||
private fun handleExistingCbzFile(cbzFile: File, chapterFolder: File) {
|
||||
if (!chapterFolder.exists()) chapterFolder.mkdirs()
|
||||
ZipInputStream(cbzFile.inputStream()).use { zipInputStream ->
|
||||
ZipArchiveInputStream(cbzFile.inputStream()).use { zipInputStream ->
|
||||
var zipEntry = zipInputStream.nextEntry
|
||||
while (zipEntry != null) {
|
||||
val file = File(chapterFolder, zipEntry.name)
|
||||
|
||||
Reference in New Issue
Block a user