Skip to content

Commit

Permalink
修改打包代码
Browse files Browse the repository at this point in the history
  • Loading branch information
4o4E committed Jun 24, 2022
1 parent a9c272a commit 8839845
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions pack/src/main/kotlin/top/e404/Pack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,23 @@ fun main() {
val file = File(folder)
withContext(Dispatchers.IO) {
FileOutputStream(zipName).use { fos ->
ZipOutputStream(fos).use { zos ->
file.zip("", zos)
}
ZipOutputStream(fos).use { zos -> file.zip(null, zos) }
}
}
}
}
}
}

suspend fun File.zip(path: String, zos: ZipOutputStream) {
suspend fun File.zip(path: String?, zos: ZipOutputStream) {
if (isDirectory) {
listFiles()?.forEach {
it.zip("$path/${it.name}", zos)
it.zip(if (path == null) it.name else "$path/${it.name}", zos)
}
return
}
withContext(Dispatchers.IO) {
zos.putNextEntry(ZipEntry(path))
zos.putNextEntry(ZipEntry(path ?: name))
inputStream().use { it.copyTo(zos) }
}
}

0 comments on commit 8839845

Please sign in to comment.