mirror of
https://github.com/null2264/yokai.git
synced 2025-06-20 10:14:50 +00:00
revert: "refactor(archive): Move stuff around"
This reverts commit e19d048bb1
.
This commit is contained in:
parent
33332110f1
commit
17eec5f6aa
4 changed files with 11 additions and 22 deletions
|
@ -53,7 +53,7 @@ class AndroidArchiveInputStream(buffer: Long, size: Long) : ArchiveInputStream()
|
|||
Archive.readFree(archive)
|
||||
}
|
||||
|
||||
override fun getNextEntry() = Archive.readNextHeader(archive).takeUnless { it == 0L }?.let { entry ->
|
||||
fun getNextEntry() = Archive.readNextHeader(archive).takeUnless { it == 0L }?.let { entry ->
|
||||
val name = ArchiveEntry.pathnameUtf8(entry) ?: ArchiveEntry.pathname(entry)?.decodeToString() ?: return null
|
||||
val isFile = ArchiveEntry.filetype(entry) == ArchiveEntry.AE_IFREG
|
||||
ArchiveEntry(name, isFile)
|
||||
|
|
|
@ -9,17 +9,15 @@ import eu.kanade.tachiyomi.util.system.openFileDescriptor
|
|||
import me.zhanghai.android.libarchive.ArchiveException
|
||||
import java.io.InputStream
|
||||
|
||||
class AndroidArchiveReader(pfd: ParcelFileDescriptor) : ArchiveReader() {
|
||||
override val size =
|
||||
pfd.statSize
|
||||
override val address =
|
||||
Os.mmap(0, size, OsConstants.PROT_READ, OsConstants.MAP_PRIVATE, pfd.fileDescriptor, 0)
|
||||
class AndroidArchiveReader(pfd: ParcelFileDescriptor) : ArchiveReader {
|
||||
val size = pfd.statSize
|
||||
val address = Os.mmap(0, size, OsConstants.PROT_READ, OsConstants.MAP_PRIVATE, pfd.fileDescriptor, 0)
|
||||
|
||||
override fun createInputStream(address: Long, size: Long): ArchiveInputStream =
|
||||
AndroidArchiveInputStream(address, size)
|
||||
override fun <T> useEntries(block: (Sequence<ArchiveEntry>) -> T): T =
|
||||
AndroidArchiveInputStream(address, size).use { block(generateSequence { it.getNextEntry() }) }
|
||||
|
||||
override fun getInputStream(entryName: String): InputStream? {
|
||||
val archive = createInputStream(address, size)
|
||||
val archive = AndroidArchiveInputStream(address, size)
|
||||
try {
|
||||
while (true) {
|
||||
val entry = archive.getNextEntry() ?: break
|
||||
|
|
|
@ -3,6 +3,4 @@ package yokai.core.archive
|
|||
import java.io.InputStream
|
||||
|
||||
// TODO: Use Okio's Source
|
||||
abstract class ArchiveInputStream : InputStream() {
|
||||
abstract fun getNextEntry(): ArchiveEntry?
|
||||
}
|
||||
abstract class ArchiveInputStream : InputStream()
|
||||
|
|
|
@ -3,14 +3,7 @@ package yokai.core.archive
|
|||
import java.io.Closeable
|
||||
import java.io.InputStream
|
||||
|
||||
abstract class ArchiveReader : Closeable {
|
||||
abstract val address: Long
|
||||
abstract val size: Long
|
||||
|
||||
abstract fun createInputStream(address: Long, size: Long): ArchiveInputStream
|
||||
|
||||
inline fun <T> useEntries(block: (Sequence<ArchiveEntry>) -> T): T =
|
||||
createInputStream(address, size).use { block(generateSequence { it.getNextEntry() }) }
|
||||
|
||||
abstract fun getInputStream(entryName: String): InputStream?
|
||||
interface ArchiveReader : Closeable {
|
||||
fun <T> useEntries(block: (Sequence<ArchiveEntry>) -> T): T
|
||||
fun getInputStream(entryName: String): InputStream?
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue