
Lightweight library facilitates reading, writing, and modifying ZIP files, offering features like easy extraction, compression, and modification of ZIP entries and metadata.
A lightweight Kotlin Multiplatform library for reading, writing and modifying ZIP files.
The Kotlin file I/O interface uses kotlinx-io making it compatible with other Kotlin Multiplatform libraries. The multiplatform implementation is tested and benchmarked against zip4j on JVM and kuba--/zip on native targets with up to 2x performance improvement.
Kzip currently supports the following targets:
More features are planned, including support for suspending functions, more access to metadata, a ZIP file system, more utilities and integrations into other KMP libraries (see also Contributing).
The kzip dependency is available on Maven Central and can be added to your common source set.
Just replace $kzipVersion with the latest version.
implementation("de.jonasbroeckmann.kzip:kzip:$kzipVersion")implementation "de.jonasbroeckmann.kzip:kzip:$kzipVersion"<dependencies>
<dependency>
<groupId>de.jonasbroeckmann.kzip</groupId>
<artifactId>kzip</artifactId>
<version>$kzipVersion</version>
</dependency>
</dependencies>val zip = Zip.open(Path("example.zip"))
// Access a specific entry
zip.entry(Path("my_compressed.txt")) {
println("Entry my_compressed.txt has size $compressedSize/$uncompressedSize")
println("Entry my_compressed.txt has content:")
println(readToSource().readString())
}
// Access all entries
zip.forEachEntry { entry ->
println("Entry ${entry.path} has size ${entry.uncompressedSize}")
if (entry.isDirectory) {
println("Entry is a directory")
} else {
println("Entry is a file with content:")
println(entry.readToSource().readString())
}
}
zip.close()Zip.open(Path("example.zip"), mode = Zip.Mode.Append).use { zip ->
// Add a folder
zip.folderEntry(Path("subfolder"))
// Add a file from a path
zip.entryFromPath(Path("subfolder", "compressed.txt"), Path("example.txt"))
// Add a file from a source
zip.entryFromSource(Path("hello_world.txt"), Buffer().apply { writeString("Hello, World!") })
// Delete an entry
zip.deleteEntries(Path("old_file.txt"))
}Zip.open(Path("example.zip")).use { zip ->
zip.extractTo(Path("example"))
}Zip.open(
path = Path("example.zip"),
mode = Zip.Mode.Write,
// Optional: Set compression level
level = Zip.CompressionLevel.BetterCompression
).use { zip ->
zip.compressFrom(Path("example"))
}If you have any ideas, feel free to open an issue or create a pull request.
This project is licensed under the MIT License.
A lightweight Kotlin Multiplatform library for reading, writing and modifying ZIP files.
The Kotlin file I/O interface uses kotlinx-io making it compatible with other Kotlin Multiplatform libraries. The multiplatform implementation is tested and benchmarked against zip4j on JVM and kuba--/zip on native targets with up to 2x performance improvement.
Kzip currently supports the following targets:
More features are planned, including support for suspending functions, more access to metadata, a ZIP file system, more utilities and integrations into other KMP libraries (see also Contributing).
The kzip dependency is available on Maven Central and can be added to your common source set.
Just replace $kzipVersion with the latest version.
implementation("de.jonasbroeckmann.kzip:kzip:$kzipVersion")implementation "de.jonasbroeckmann.kzip:kzip:$kzipVersion"<dependencies>
<dependency>
<groupId>de.jonasbroeckmann.kzip</groupId>
<artifactId>kzip</artifactId>
<version>$kzipVersion</version>
</dependency>
</dependencies>val zip = Zip.open(Path("example.zip"))
// Access a specific entry
zip.entry(Path("my_compressed.txt")) {
println("Entry my_compressed.txt has size $compressedSize/$uncompressedSize")
println("Entry my_compressed.txt has content:")
println(readToSource().readString())
}
// Access all entries
zip.forEachEntry { entry ->
println("Entry ${entry.path} has size ${entry.uncompressedSize}")
if (entry.isDirectory) {
println("Entry is a directory")
} else {
println("Entry is a file with content:")
println(entry.readToSource().readString())
}
}
zip.close()Zip.open(Path("example.zip"), mode = Zip.Mode.Append).use { zip ->
// Add a folder
zip.folderEntry(Path("subfolder"))
// Add a file from a path
zip.entryFromPath(Path("subfolder", "compressed.txt"), Path("example.txt"))
// Add a file from a source
zip.entryFromSource(Path("hello_world.txt"), Buffer().apply { writeString("Hello, World!") })
// Delete an entry
zip.deleteEntries(Path("old_file.txt"))
}Zip.open(Path("example.zip")).use { zip ->
zip.extractTo(Path("example"))
}Zip.open(
path = Path("example.zip"),
mode = Zip.Mode.Write,
// Optional: Set compression level
level = Zip.CompressionLevel.BetterCompression
).use { zip ->
zip.compressFrom(Path("example"))
}If you have any ideas, feel free to open an issue or create a pull request.
This project is licensed under the MIT License.