https://github.com/rushiimachine/zip-android
Native zip library + java interface for android
https://github.com/rushiimachine/zip-android
android java kotlin rust zip
Last synced: 4 months ago
JSON representation
Native zip library + java interface for android
- Host: GitHub
- URL: https://github.com/rushiimachine/zip-android
- Owner: rushiiMachine
- License: apache-2.0
- Created: 2022-03-17T05:02:05.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-07-09T03:00:51.000Z (4 months ago)
- Last Synced: 2025-07-19T10:23:53.995Z (4 months ago)
- Topics: android, java, kotlin, rust, zip
- Language: Rust
- Homepage:
- Size: 438 KB
- Stars: 7
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# zip-android 
Android JNI bindings for [zip-rs](https://github.com/zip-rs/zip), a native rust zip library.
This has significant performance improvements compared to similar libraries
written in JVM languages.
### Prerequisites
- Android 5 - 16 (API 21 - 36)
- `x86`, `x86_64`, `armeabiv7`, `arm64`, `riscv64`
- 4KiB or 16KiB page alignment
### Installation
```kotlin
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.diamondminer88:zip-android:2.3.1")
}
```
### Example Usage (Kotlin)
```kotlin
// Open a zip reader from a java.io.File to be read from disk
// You can autoclose reader/writer by using .use {} (kotlin) or .close()/try block for java
ZipReader(file).use { zip ->
"Entry count: ${zip.entryCount}"
"Entries: ${zip.entryNames.joinToString()}"
// Loop over entries
zip.entries().forEach { /* guh */ }
zip.forEach {
"Entry: ${it.name} size: ${it.size} modified: ${it.lastModified}"
if (it.isFile) {
"Content: ${it.read().decodeToString()}"
}
}
}
// Open zip reader from an in memory byte array
ZipReader(byteArrayOf(/* ... */)).use { zip ->
// Parsed in-memory zip!
}
// Open a zip writer to the specified java.io.File path and overwrite the original file
// If you wish to append to an existing zip at that location, set the append parameter to `true`.
ZipWriter(file, /* append = */ false).use { zip ->
zip.setComment("a comment".toByteArray())
zip.writeEntry("compressed.txt", "hot garbage")
zip.writeEntry("data/compressed_bytes.txt", bytes)
zip.writeDir("com/github/diamondminer88/zip")
zip.deleteEntries("abc.txt", "guh.txt")
zip.deleteEntry("husk.txt")
// Write page-aligned (4096 byte) uncompressed entry (useful for writing zip aligned .so's)
zip.writeEntry("lib.so", bytes, ZipCompression.NONE, 4096)
// Delete entry from central dir, preserving alignment for all existing zip entries
// If fillVoid is false, then it un-aligns all entries whose data comes after this one
zip.deleteEntry("lib.so", /* fillVoid = */ true)
}
// Start a new in-memory zip file
val newZipBytes = ZipWriter().use { zip ->
// ...
zip.toByteArray() // Closes the zip and retrieves the bytes
}
// Open and append to an existing zip from an in memory byte array
val modifiedZipBytes = ZipWriter(byteArrayOf(/* ... */)).use { zip ->
// ...
zip.toByteArray() // Closes the zip and retrieves the modified zip file bytes
}
```
The available compression methods are: `Stored` (none), `Deflate` (default), `Bzip2`, and `Zstd`.
### Building Prerequisites
1. `rustup install nightly && rustup default nightly`
2.
`rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android`
3. `cargo install --force cargo-ndk`