|
@@ -10,7 +10,7 @@ import io.legado.app.lib.icu4j.CharsetDetector
|
|
|
import me.zhanghai.android.libarchive.Archive
|
|
import me.zhanghai.android.libarchive.Archive
|
|
|
import me.zhanghai.android.libarchive.ArchiveEntry
|
|
import me.zhanghai.android.libarchive.ArchiveEntry
|
|
|
import me.zhanghai.android.libarchive.ArchiveException
|
|
import me.zhanghai.android.libarchive.ArchiveException
|
|
|
-import splitties.init.appCtx
|
|
|
|
|
|
|
+import okio.Buffer
|
|
|
import java.io.File
|
|
import java.io.File
|
|
|
import java.io.FileDescriptor
|
|
import java.io.FileDescriptor
|
|
|
import java.io.IOException
|
|
import java.io.IOException
|
|
@@ -24,8 +24,6 @@ import java.nio.charset.StandardCharsets
|
|
|
|
|
|
|
|
object LibArchiveUtils {
|
|
object LibArchiveUtils {
|
|
|
|
|
|
|
|
- val cachePath = File(appCtx.cacheDir, "archive")
|
|
|
|
|
-
|
|
|
|
|
@Throws(ArchiveException::class)
|
|
@Throws(ArchiveException::class)
|
|
|
fun openArchive(
|
|
fun openArchive(
|
|
|
inputStream: InputStream,
|
|
inputStream: InputStream,
|
|
@@ -153,7 +151,7 @@ object LibArchiveUtils {
|
|
|
val buffer = ByteBuffer.allocateDirect(DEFAULT_BUFFER_SIZE)
|
|
val buffer = ByteBuffer.allocateDirect(DEFAULT_BUFFER_SIZE)
|
|
|
Archive.readSetReadCallback<Any>(
|
|
Archive.readSetReadCallback<Any>(
|
|
|
archive
|
|
archive
|
|
|
- ) { _1: Long, fd: Any? ->
|
|
|
|
|
|
|
+ ) { _: Long, fd: Any? ->
|
|
|
buffer.clear()
|
|
buffer.clear()
|
|
|
try {
|
|
try {
|
|
|
Os.read(fd as FileDescriptor?, buffer)
|
|
Os.read(fd as FileDescriptor?, buffer)
|
|
@@ -167,7 +165,7 @@ object LibArchiveUtils {
|
|
|
}
|
|
}
|
|
|
Archive.readSetSkipCallback<Any>(
|
|
Archive.readSetSkipCallback<Any>(
|
|
|
archive
|
|
archive
|
|
|
- ) { _1: Long, fd: Any?, request: Long ->
|
|
|
|
|
|
|
+ ) { _: Long, fd: Any?, request: Long ->
|
|
|
try {
|
|
try {
|
|
|
Os.lseek(
|
|
Os.lseek(
|
|
|
fd as FileDescriptor?, request, OsConstants.SEEK_CUR
|
|
fd as FileDescriptor?, request, OsConstants.SEEK_CUR
|
|
@@ -179,7 +177,7 @@ object LibArchiveUtils {
|
|
|
}
|
|
}
|
|
|
Archive.readSetSeekCallback<Any>(
|
|
Archive.readSetSeekCallback<Any>(
|
|
|
archive
|
|
archive
|
|
|
- ) { _1: Long, fd: Any?, offset: Long, whence: Int ->
|
|
|
|
|
|
|
+ ) { _: Long, fd: Any?, offset: Long, whence: Int ->
|
|
|
try {
|
|
try {
|
|
|
return@readSetSeekCallback Os.lseek(
|
|
return@readSetSeekCallback Os.lseek(
|
|
|
fd as FileDescriptor?, offset, whence
|
|
fd as FileDescriptor?, offset, whence
|
|
@@ -304,18 +302,17 @@ object LibArchiveUtils {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (entryName == path) {
|
|
if (entryName == path) {
|
|
|
- cachePath.mkdirs()
|
|
|
|
|
- val entryFile = File(cachePath, entry.toString())
|
|
|
|
|
- entryFile.delete()
|
|
|
|
|
- entryFile.createNewFile()
|
|
|
|
|
- entryFile.setReadable(true)
|
|
|
|
|
- entryFile.setExecutable(true)
|
|
|
|
|
- ParcelFileDescriptor.open(entryFile, ParcelFileDescriptor.MODE_WRITE_ONLY).use {
|
|
|
|
|
- Archive.readDataIntoFd(archive, it.fd)
|
|
|
|
|
|
|
+ val byteBuffer = ByteBuffer.allocateDirect(DEFAULT_BUFFER_SIZE)
|
|
|
|
|
+ val buffer = Buffer()
|
|
|
|
|
+ while (true) {
|
|
|
|
|
+ Archive.readData(archive, byteBuffer)
|
|
|
|
|
+ byteBuffer.flip()
|
|
|
|
|
+ if (!byteBuffer.hasRemaining()) {
|
|
|
|
|
+ return buffer.readByteArray()
|
|
|
|
|
+ }
|
|
|
|
|
+ buffer.write(byteBuffer)
|
|
|
|
|
+ byteBuffer.clear()
|
|
|
}
|
|
}
|
|
|
- val bytes = entryFile.readBytes()
|
|
|
|
|
- entryFile.delete()
|
|
|
|
|
- return bytes
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
entry = Archive.readNextHeader(archive)
|
|
entry = Archive.readNextHeader(archive)
|