All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.co.touchlab.skie.plugin.util.JarUtils.kt Maven / Gradle / Ivy

There is a newer version: 0.9.0-RC.5
Show newest version
package co.touchlab.skie.plugin.util

import java.io.File
import java.net.URI
import java.nio.file.FileSystem
import java.nio.file.FileSystemNotFoundException
import java.nio.file.FileSystems

fun File.writeToZip(write: (FileSystem) -> Unit) {
    val fileUri = this.toURI()

    // Solves an issues with spaces in the path
    val uri = URI("jar:file", fileUri.userInfo, fileUri.host, fileUri.port, fileUri.path, fileUri.query, fileUri.fragment)

    val fileSystem = try {
        FileSystems.getFileSystem(uri)
    } catch (_: FileSystemNotFoundException) {
        FileSystems.newFileSystem(uri, mapOf("create" to true))
    }

    fileSystem.use(write)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy