Skip to content

Commit

Permalink
// wip zip
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFruxz committed Mar 18, 2024
1 parent 4b9be76 commit c0cbd81
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/kotlin/dev/fruxz/ascend/tool/zip/Zip.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.io.FileInputStream
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.StandardCopyOption
import java.nio.file.StandardOpenOption
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
import java.util.zip.ZipOutputStream
Expand Down Expand Up @@ -90,12 +91,15 @@ object Zip {

if (!targetFile.startsWith(targetFile)) throw SecurityException("Entry is outside of the target directory! (java/zipslip)")

targetFile.createParentDirectories()
if (entry.isDirectory) {
Files.createDirectories(targetFile)
} else {
Files.createDirectories(targetFile.parent)
Files.copy(zipFile.getInputStream(entry), targetFile, StandardCopyOption.REPLACE_EXISTING)
target.createDirectory()
return@forEach
}

zipFile
.getInputStream(entry)
.copyTo(targetFile.outputStream(StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING))
}
}

Expand Down

0 comments on commit c0cbd81

Please sign in to comment.