Skip to content

Commit

Permalink
Use okio to unzip files
Browse files Browse the repository at this point in the history
  • Loading branch information
juraj-hrivnak committed Jul 23, 2024
1 parent c790651 commit 005c15e
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/commonMain/kotlin/teksturepako/pakku/io/Zip.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
package teksturepako.pakku.io

import korlibs.io.file.VfsFile
import korlibs.io.file.std.localCurrentDirVfs
import korlibs.io.file.std.openAsZip
import com.github.michaelbull.result.get
import com.github.michaelbull.result.runCatching
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okio.FileSystem
import okio.Path.Companion.toOkioPath
import okio.Path.Companion.toPath
import okio.openZip
import java.io.BufferedOutputStream
import java.io.File
import java.io.FileOutputStream
import java.nio.file.Path
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream

suspend fun unzip(path: String): VfsFile
{
val file = localCurrentDirVfs[path]
return file.openAsZip()
}
fun readPathTextFromZip(zipPath: Path, filePath: Path): String? = runCatching {
FileSystem.SYSTEM.openZip(zipPath.toOkioPath()).read(filePath.toOkioPath()) { readUtf8() }
}.get()

fun readPathTextFromZip(zipPath: Path, filePath: String): String? = runCatching {
FileSystem.SYSTEM.openZip(zipPath.toOkioPath()).read(filePath.toPath()) { readUtf8() }
}.get()

suspend fun zip(inputDirectory: Path, outputZipFile: Path) = withContext(Dispatchers.IO) {
val inputFile = inputDirectory.toFile()
Expand Down

0 comments on commit 005c15e

Please sign in to comment.