Fix RAR loading
Closes #10302 (cherry picked from commit 80b7d14af195147b52e38765fdb3adf4b9030dd4) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/RarPageLoader.kt
This commit is contained in:
parent
8adad251a0
commit
e873557066
@ -14,6 +14,7 @@ import java.io.File
|
|||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.io.PipedInputStream
|
import java.io.PipedInputStream
|
||||||
import java.io.PipedOutputStream
|
import java.io.PipedOutputStream
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loader used to load a chapter from a .rar or .cbr file.
|
* Loader used to load a chapter from a .rar or .cbr file.
|
||||||
@ -50,6 +51,11 @@ internal class RarPageLoader(file: File) : PageLoader() {
|
|||||||
|
|
||||||
override var isLocal: Boolean = true
|
override var isLocal: Boolean = true
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pool for copying compressed files to an input stream.
|
||||||
|
*/
|
||||||
|
private val pool = Executors.newFixedThreadPool(1)
|
||||||
|
|
||||||
override suspend fun getPages(): List<ReaderPage> {
|
override suspend fun getPages(): List<ReaderPage> {
|
||||||
// SY -->
|
// SY -->
|
||||||
if (readerPreferences.cacheArchiveMangaOnDisk().get()) {
|
if (readerPreferences.cacheArchiveMangaOnDisk().get()) {
|
||||||
@ -61,7 +67,7 @@ internal class RarPageLoader(file: File) : PageLoader() {
|
|||||||
.sortedWith { f1, f2 -> f1.fileName.compareToCaseInsensitiveNaturalOrder(f2.fileName) }
|
.sortedWith { f1, f2 -> f1.fileName.compareToCaseInsensitiveNaturalOrder(f2.fileName) }
|
||||||
.mapIndexed { i, header ->
|
.mapIndexed { i, header ->
|
||||||
ReaderPage(i).apply {
|
ReaderPage(i).apply {
|
||||||
stream = { getStream(rar, header) }
|
stream = { getStream(header) }
|
||||||
status = Page.State.READY
|
status = Page.State.READY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,15 +84,16 @@ internal class RarPageLoader(file: File) : PageLoader() {
|
|||||||
// SY -->
|
// SY -->
|
||||||
tmpDir.deleteRecursively()
|
tmpDir.deleteRecursively()
|
||||||
// SY <--
|
// SY <--
|
||||||
|
pool.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an input stream for the given [header].
|
* Returns an input stream for the given [header].
|
||||||
*/
|
*/
|
||||||
private fun getStream(rar: Archive, header: FileHeader): InputStream {
|
private fun getStream(header: FileHeader): InputStream {
|
||||||
val pipeIn = PipedInputStream()
|
val pipeIn = PipedInputStream()
|
||||||
val pipeOut = PipedOutputStream(pipeIn)
|
val pipeOut = PipedOutputStream(pipeIn)
|
||||||
synchronized(this) {
|
pool.execute {
|
||||||
try {
|
try {
|
||||||
pipeOut.use {
|
pipeOut.use {
|
||||||
rar.extractFile(header, it)
|
rar.extractFile(header, it)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user