diff --git a/src/main/kotlin/ley/anvil/modpacktools/util/Util.kt b/src/main/kotlin/ley/anvil/modpacktools/util/Util.kt index 1de96dd..8b444ac 100644 --- a/src/main/kotlin/ley/anvil/modpacktools/util/Util.kt +++ b/src/main/kotlin/ley/anvil/modpacktools/util/Util.kt @@ -9,11 +9,12 @@ import okhttp3.MediaType import okhttp3.MediaType.Companion.toMediaType import okhttp3.Request import okhttp3.RequestBody.Companion.toRequestBody -import java.io.File -import java.io.FileReader -import java.io.IOException +import java.io.* import java.net.URI import java.net.URL +import java.util.zip.ZipEntry +import java.util.zip.ZipOutputStream + /** * Reads a Json File @@ -87,4 +88,24 @@ fun URL.sanitize(): URL? { } catch(e: Exception) { null } +} + +fun zipDir(dir: File, parent: String?, zip: ZipOutputStream) { + for (file in dir.listFiles()){ + println(file.name) + if (file.isDirectory) { + zipDir(file, parent + file.name + "/", zip) + continue + } + zip.putNextEntry(ZipEntry(parent + file.name)) + var inp = BufferedInputStream(FileInputStream(file)) + var bytesRead: Long = 0 + val bytesIn = ByteArray(4096) + var read = 0 + while (inp.read(bytesIn).also { read = it } != -1) { + zip.write(bytesIn, 0, read) + bytesRead += read.toLong() + } + zip.closeEntry() + } } \ No newline at end of file