summaryrefslogtreecommitdiff
path: root/plugin/src/main/kotlin/moe/nea/archenemy/util/FSUtil.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2023-12-14 18:11:17 +0100
committerLinnea Gräf <nea@nea.moe>2023-12-14 18:11:17 +0100
commita453cc833f52cf1ccd52288edb73c6f0fbc0c7cc (patch)
tree27704f77968903b7fb38debf42cefda7ed85b705 /plugin/src/main/kotlin/moe/nea/archenemy/util/FSUtil.kt
parent9058126b0d77c315436226a589ade0748d8a2905 (diff)
downloadarchenemy-a453cc833f52cf1ccd52288edb73c6f0fbc0c7cc.tar.gz
archenemy-a453cc833f52cf1ccd52288edb73c6f0fbc0c7cc.tar.bz2
archenemy-a453cc833f52cf1ccd52288edb73c6f0fbc0c7cc.zip
Add support for jar merging
Diffstat (limited to 'plugin/src/main/kotlin/moe/nea/archenemy/util/FSUtil.kt')
-rw-r--r--plugin/src/main/kotlin/moe/nea/archenemy/util/FSUtil.kt33
1 files changed, 33 insertions, 0 deletions
diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/util/FSUtil.kt b/plugin/src/main/kotlin/moe/nea/archenemy/util/FSUtil.kt
new file mode 100644
index 0000000..0b2f70e
--- /dev/null
+++ b/plugin/src/main/kotlin/moe/nea/archenemy/util/FSUtil.kt
@@ -0,0 +1,33 @@
+package moe.nea.archenemy.util
+
+import java.io.InputStream
+import java.net.URI
+import java.nio.file.FileSystem
+import java.nio.file.FileSystems
+import java.nio.file.Path
+import java.util.zip.ZipInputStream
+import java.util.zip.ZipOutputStream
+import kotlin.io.path.createDirectories
+import kotlin.io.path.exists
+import kotlin.io.path.inputStream
+import kotlin.io.path.outputStream
+
+// TODO: Figure out license shit with unimined cause i copied some of these utils?
+fun Path.zipFs(): FileSystem {
+ if (!exists()) {
+ parent.createDirectories()
+ ZipOutputStream(this.outputStream()).use { }
+ }
+ return FileSystems.newFileSystem(URI.create("jar:${toUri()}"), mapOf("create" to true), null)
+}
+
+fun Path.readZipFs(reader: (String, InputStream) -> Unit) {
+ ZipInputStream(this.inputStream()).use { stream ->
+ for (entry in generateSequence { stream.nextEntry }) {
+ if (entry.isDirectory) {
+ continue
+ }
+ reader(entry.name, stream)
+ }
+ }
+}