don't read the entire archive into memory

This commit is contained in:
AbdallahMehiz 2024-01-29 15:17:47 +01:00
parent ffcba7b2dc
commit 415124d20e
No known key found for this signature in database
GPG Key ID: 975266399F5BAF34
2 changed files with 6 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.reader.loader package eu.kanade.tachiyomi.ui.reader.loader
import android.content.Context import android.content.Context
import android.os.ParcelFileDescriptor.AutoCloseInputStream
import com.github.junrar.exception.UnsupportedRarV5Exception import com.github.junrar.exception.UnsupportedRarV5Exception
import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.download.DownloadProvider import eu.kanade.tachiyomi.data.download.DownloadProvider
@ -105,7 +106,8 @@ class ChapterLoader(
is Format.Directory -> DirectoryPageLoader(format.file) is Format.Directory -> DirectoryPageLoader(format.file)
is Format.Zip -> ZipPageLoader(tempFileManager.createTempFile(format.file)) is Format.Zip -> ZipPageLoader(tempFileManager.createTempFile(format.file))
is Format.SevenZip -> try { is Format.SevenZip -> try {
SevenZipPageLoader(format.file) { val file = context.contentResolver.openFileDescriptor(format.file.uri, "r")
SevenZipPageLoader(AutoCloseInputStream(file)) {
GlobalScope.launchUI { GlobalScope.launchUI {
context.toast(context.stringResource(MR.strings.loader_7zip_slow_archives, it)) context.toast(context.stringResource(MR.strings.loader_7zip_slow_archives, it))
} }

View File

@ -1,21 +1,20 @@
package eu.kanade.tachiyomi.ui.reader.loader package eu.kanade.tachiyomi.ui.reader.loader
import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
import eu.kanade.tachiyomi.util.storage.SevenZUtil.getImages import eu.kanade.tachiyomi.util.storage.SevenZUtil.getImages
import org.apache.commons.compress.archivers.sevenz.SevenZFile import org.apache.commons.compress.archivers.sevenz.SevenZFile
import org.apache.commons.compress.utils.SeekableInMemoryByteChannel import java.io.FileInputStream
/** /**
* Loader used to load a chapter from a .7z or .cb7 file. * Loader used to load a chapter from a .7z or .cb7 file.
*/ */
internal class SevenZipPageLoader( internal class SevenZipPageLoader(
private val file: UniFile, private val file: FileInputStream,
private val notifySlowArchive: (method: String) -> Unit, private val notifySlowArchive: (method: String) -> Unit,
) : PageLoader() { ) : PageLoader() {
private val zip by lazy { SevenZFile(SeekableInMemoryByteChannel(file.openInputStream().readBytes())) } private val zip by lazy { SevenZFile(file.channel) }
override var isLocal: Boolean = true override var isLocal: Boolean = true